SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 t-sql 2008 next case statements
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

325 Posts

Posted - 02/23/2014 :  23:42:01  Show Profile  Reply with Quote
I have a question about understanding nested case statements in sql server 2008:
The sql looks like the folloiwng:
select numberofcases
from inventory
where inventory_cnt > 1000
(when select top 1
from inventory
where inventory_cnt > 750
then numberofcases = 750 * 30
when select top 2
from inventory
where inventory_cnt > 975
then numberofcases = 975 * 35
when select top 3
from inventory
where inventory_cnt > 1025
then numberofcases = 1025 / 10
when select top 4
from inventory
where inventory_cnt > 1050
then numberofcases = 1050 / 5) c * 2
as casesused, select CustomerNumber from inventory

I would like you to explain the following:
1. There are 4 when statements. Will the logic hit each when statemnet or will the logic
stop once the first when statement is true?
2. Would you explain what the c* 2 means from the school listed above?

In (Som, Ni, Yak)

17684 Posts

Posted - 02/23/2014 :  23:48:26  Show Profile  Reply with Quote
is that a complete workable query ?

Time is always against us

Go to Top of Page

Constraint Violating Yak Guru

325 Posts

Posted - 02/24/2014 :  10:12:37  Show Profile  Reply with Quote
found answer
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

1827 Posts

Posted - 02/24/2014 :  18:59:20  Show Profile  Reply with Quote
Thanks for sharing...

There are two kinds of light -- the glow that illuminates, and the glare that obscures. -James Thurber (1894-1961)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000