Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 t-sql 2008 next case statements

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2014-02-23 : 23:42:01
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?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-23 : 23:48:26
is that a complete workable query ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2014-02-24 : 10:12:37
found answer
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-02-24 : 18:59:20
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
   

- Advertisement -