Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss content posted by Amit mishra
»
case statement puzzle
17 posts, Page 1 of 2
1
2
»»
case statement puzzle
Rate Topic
Display Mode
Topic Options
Author
Message
amit_adarsh
amit_adarsh
Posted Tuesday, May 25, 2010 9:35 PM
Say Hey Kid
Group: General Forum Members
Last Login: Monday, March 11, 2013 4:12 AM
Points: 664,
Visits: 138
Comments posted to this topic are about the item
case statement puzzle
Post #927926
Koen Verbeeck
Koen Verbeeck
Posted Wednesday, May 26, 2010 12:50 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 9:06 AM
Points: 9,367,
Visits: 6,465
Nice question. I didn't know that constants (like 1) could be placed after CASE, so I definately learned something today.
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #927974
sharath.chalamgari
sharath.chalamgari
Posted Wednesday, May 26, 2010 1:31 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, September 17, 2012 7:30 AM
Points: 1,038,
Visits: 679
Nice Question,
as you said once the condition is satisfied it will not look at other statement.
Post #927996
Andrew Watson-478275
Andrew Watson-478275
Posted Wednesday, May 26, 2010 3:25 AM
SSC Eights!
Group: General Forum Members
Last Login: Saturday, May 18, 2013 1:44 AM
Points: 953,
Visits: 1,875
I really need to stop being so mistrusting. The right answer was so obvious, I assumed it had to be a trick question and got it wrong
.
Post #928055
DugyC
DugyC
Posted Wednesday, May 26, 2010 3:29 AM
Ten Centuries
Group: General Forum Members
Last Login: Today @ 5:21 AM
Points: 1,162,
Visits: 728
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.
_____________________________________________________________________
"The difficult tasks we do immediately, the impossible takes a little longer"
Post #928059
Ujar
Ujar
Posted Wednesday, May 26, 2010 7:59 AM
SSC Rookie
Group: General Forum Members
Last Login: Tuesday, October 12, 2010 4:24 AM
Points: 41,
Visits: 102
Really a nice question..
I have got the confusion that, we need to declare the variable name followed by case statement and after that the value followed by when.
Thanks..
Post #928282
Steve Jones - SSC Editor
Steve Jones - SSC Editor
Posted Wednesday, May 26, 2010 9:13 AM
SSC-Dedicated
Group: Administrators
Last Login: Yesterday @ 2:54 PM
Points: 31,410,
Visits: 13,726
This one reminds me of the fundamental concepts I learned in C. 0=false, 1=true.
Follow me on Twitter:
@way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
Post #928364
ken.trock
ken.trock
Posted Wednesday, May 26, 2010 9:24 AM
Old Hand
Group: General Forum Members
Last Login: Yesterday @ 2:37 PM
Points: 315,
Visits: 1,353
da-zero (5/26/2010)
Nice question. I didn't know that constants (like 1) could be placed after CASE, so I definately learned something today.
Yeah, same here. Good thing a 4th choice like "error" wasn't supplied with the question or I might have gotten it wrong
Post #928380
brdudley
brdudley
Posted Wednesday, May 26, 2010 10:35 AM
Ten Centuries
Group: General Forum Members
Last Login: Yesterday @ 10:18 AM
Points: 1,232,
Visits: 1,392
Steve Jones - Editor (5/26/2010)
This one reminds me of the fundamental concepts I learned in C. 0=false, 1=true.
If you are saying that it chooses the first one because 1 = true, that is not correct. It is using the Case syntax similar to a Switch statement. The Select is equivalent to
Select Case
When @flg = 1 then 'True'
When @flg = 1 then 'False'
Else 'No Flag'
Try changing the constant or the value of @flg. It will result in "No Flag"
Post #928451
SQLRNNR
SQLRNNR
Posted Wednesday, May 26, 2010 11:15 AM
SSCoach
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
Interesting. I did not know that a case could be written this way as well.
Thanks.
Jason
AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #928476
« Prev Topic
|
Next Topic »
17 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.