Tags

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


SQL Puzzle | The Cast Puzzle [Minimum Changes]

This puzzle is really cool. You have to fix the query to make it work with minimum changes in the query.

Please check out the current output, expected output & the query to fix below-

Current Output

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.

Expected Output

Data
2016-07-18 08:09:13.310
93.1123
A
2016-07-18 08:09:13.310
पवन
NULL

Rules/Restrictions

  • The solution should be should use “SELECT” statement or a CTE.
  • Add your solution(s) in the comments section or send you solution(s) to pawankkmr@gmail.com

Query to Fix


--

SELECT GETDATE()
UNION ALL
SELECT 93.1123
UNION ALL
SELECT 'A'
UNION ALL
SELECT GETDATE()
UNION ALL
SELECT 'पवन'
UNION ALL
SELECT NULL


--

Solution 1


--

SELECT CAST(GETDATE() AS SQL_VARIANT) Data
UNION ALL
SELECT 93.1123
UNION ALL
SELECT 'A' 
UNION ALL
SELECT GETDATE() 
UNION ALL
SELECT N'पवन'
UNION ALL
SELECT NULL

--

Add a comment if you have any other solution in mind. I would love to learn it. We all need to learn.

Enjoy !!! Keep Learning

Pawan Khowal 

Http://MSBISkills.com

Advertisements