August 1, 2011 at 12:09 pm
I see one of our query is like below:
select Cast(Case BusCalItemID
when BusCalItemID then 0
else 1
End as bit) as linked
from dbo.businessCalendarItem.....
The BusCalItemID field is a PK and int field.
My question is what does the: when BusCalItemID mean in above statement?
Thanks
August 1, 2011 at 12:27 pm
sqlfriends (8/1/2011)
I see one of our query is like below:select Cast(Case BusCalItemID
when BusCalItemID then 0
else 1
End as bit) as linked
from dbo.businessCalendarItem.....
The BusCalItemID field is a PK and int field.
My question is what does the: when BusCalItemID mean in above statement?
Thanks
WOW that is odd!!! The code is to evaluate the value of BusCalItemID and when it equals BusCalItemID then 0 else 1. That will always evaluate to 0. It is checking the value of a column and when that value it equal to itself return 0.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 1, 2011 at 12:30 pm
Sorry, I further look at the query I should make it exactly as it is:
It looks like it compares different tables
Select Cast(CASE bcd.BusCalItemID
WHEN bci.BusCalItemID THEN 0
ELSE 1
END as bit) as Linked
, Cast(CASE bcd.BusCalItemID
WHEN bci.BusCalItemID THEN null
ELSE bcd.BusCalDateID
END as int) as LinkedBusCalDateID
FROM
dbo.appBusinessCalendarItemAttribute bcia JOIN
dbo.appBusinessCalendarDate bcd ON
bcia.BusCalDateID = bcd.BusCalDateID JOIN
dbo.appBusinessCalendarItem bci ON
bcia.BusCalItemID = bci.BusCalItemID JOIN
dbo.appBusinessCalendarAttribute bca ON
bcia.BusCalAttrID = bca.BusCalAttrID
August 1, 2011 at 12:32 pm
Yes in this case it is comparing the value from one table to another. So you get what is happening now?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 1, 2011 at 12:34 pm
Yes, thanks, I have never seen before using Case to compare table values, learn something new.
August 2, 2011 at 11:50 pm
Sean Lange (8/1/2011)
WOW that is odd!!! The code is to evaluate the value of BusCalItemID and when it equals BusCalItemID then 0 else 1. That will always evaluate to 0. It is checking the value of a column and when that value it equal to itself return 0.
It will return 1 if BusCalItemID is NULL.
This seems like an odd way to test for NULL, but there you go.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply