sql - Unexpected output when using a CASE statement -
sql - Unexpected output when using a CASE statement -
i trying out random things using case statement when stumbled upon scenario. first statement throws error sec 1 works fine. can help me understand execution of case statement here.
select case when 1 = 1 'case 1' when 2 = 2 2 else 10 end select case when 1 = 1 1 when 2 = 2 'case 2' else 10 end
a case statement cannot homecoming more 1 single type. when there mix of types such int , varchar, type int has higher precedence , hence chosen type homecoming type of case statements. see http://msdn.microsoft.com/en-us/library/ms190309.aspx list of info type precedence.
your sec case statement fail if seek homecoming sec value ('case 2'
); illustration with:
select case when 1=0 1 when 2=2 'case 2' else 10 end
sql sql-server tsql
Comments
Post a Comment