## case statement puzzle

 Author Message sknox SSCertifiable Group: General Forum Members Points: 6994 Visits: 3161 F1Droid (5/26/2010)Good question that in its simplicity makes you question what seems the obvious answer and think about it more deeply.According to SQL Books Online, the parser actually checks all conditions and returns the first true condition, if none then returns "else" if its coded otherwise NULL. That's how it seems to be described.Yeah, I had the right answer in 5 seconds, but took another 3 minutes to answer the question because I was sure it couldn't be that simple...As for the Books Online reference, anyone know of a good way to introduce a condition with side-effects so we could verify if it does indeed check all conditions? Daniel Bowlin SSCoach Group: General Forum Members Points: 17644 Visits: 2629 I was thinking it has to be true, but wait....... So I spent a few more minutes thinking, only to come to the same conclusion. schultkl SSC Journeyman Group: General Forum Members Points: 80 Visits: 35 The BOL seems to imply the 1 in "CASE 1" might be interpreted as a bit constant. Is this true? It seems 0/1 values are bit constants.Note: It would not change the answer in this case due to the implicit conversion, but like others I was mistrusting and looking at it from all different angles. Just curious from an understanding standpoint. rajputrahulg Forum Newbie Group: General Forum Members Points: 3 Visits: 9 Thanks for explaining the example clearly. I answered it correctly but through some different logic. after your explaination, I understand my mistake SQL-DBA-01 SSCoach Group: General Forum Members Points: 19247 Visits: 3813 The question was pretty simple.....! But I really liked it.Since the @flg is defined with value = 1 and it is matching 1 again in Case statement so result should be obviously 'true'.Nice question...keep posting more question.... {{{{Declare @flg as int SEt @flg = 1select case 1 when @flg then 'true' when @flg then 'false' else 'noflg' }}}}end as flag Thanks. UMG Developer SSCertifiable Group: General Forum Members Points: 7304 Visits: 2204 Good question, thanks! I'm actually a little surprised that most people got it correct. :-) VM-723206 SSCommitted Group: General Forum Members Points: 1648 Visits: 267 Nice question!