November 30, 2007 at 7:09 am
it's kinda straightforward i think; a case statement can return only one datatype.
when the case is constructed, i think it is assuming the first item int he case statement will be the datatype to use.
since one of the items is a column of a different type, it assumes it needs to convert it, and fails.
here'sa a more basic example with hardcoded values: it blows up on some conversions.
a case statement must be used in relation to data; an IF statement does not, so you don't have that problem with an IF statement.
declare @id int
set @id=1
select case @id
when 1 then 64
when 2 then 'apples'
when 3 then getdate() end
set @id=2
select case @id
when 1 then 64
when 2 then 'apples'
when 3 then getdate() end
set @id=3
select case @id
when 1 then 64
when 2 then 'apples'
when 3 then getdate() end
Lowell
November 30, 2007 at 7:29 am
And also comparing an integer with a GUID is not allowed (as integer has higher precedence over GUID and GUID is not a valid integer), which is the case here.
Its not actually about EXPLICIT comparison, rather EXPLICIT conversion..:cool:
Too much coffee late in the day:w00t:
--Ramesh
November 30, 2007 at 8:58 am
Tnx for answering all.
Greetz,
Hans Brouwer
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply