Groups | Blog | Home
all groups > sql server new users > january 2007 >

sql server new users : Case Range


Jens
1/22/2007 5:18:17 AM
Hi,

try this here:

SELECT LedgerKey, PolType, Exec_Code,
CASE PolType
WHEN 'PC' THEN
CASE Exec_Code
WHEN 1840 THEN EXEC_CODE
WHEN 1850 THEN EXEC_CODE
WHEN 1880 THEN EXEC_CODE
ELSE
CASE
WHEN (Exec_Code< 2000 AND Exec_Code>900) THEN 1900
ELSE 1800
END
END
END AS MapExec



HTH, jens K. Suessmeyer.

---
http://www.sqlserver2005.de
---
Roy Harvey
1/22/2007 8:58:22 AM
[quoted text, click to view]

Use the other version of the CASE expression, where each WHEN clause
is a full test.

CASE WHEN EXEC_CODE IN (1840, 1850 or 1880)
THEN EXEC_CODE
WHEN EXEC_CODE BETWEEN 900 AND 2000
THEN 1900
ELSE 1800
END

Roy Harvey
Vayse
1/22/2007 12:54:04 PM
I want to run a Case statement. If the Exec Code is 1840, 1850 or 1880 then
use that Exec Code.
Otherwise, if the the Exec_Code is between 900 and 2000, use 1900 as the
value.
If none or the above, use 1800.
How do I use < or > in the Case/When statement?
Thanks
Vayse

SELECT LedgerKey, PolType, Exec_Code,

CASE PolType
WHEN 'PC' THEN
CASE Exec_Code
WHEN 1840 THEN EXEC_CODE
WHEN 1850 THEN EXEC_CODE
WHEN 1880 THEN EXEC_CODE
ELSE
CASE Exec_Code
WHEN < 2000 AND >900 THEN 1900 '**** PROBLEM
ELSE 1800
END
END
END AS MapExec




Vayse
1/22/2007 4:59:12 PM
Thanks Roy and Jens - its working now.

[quoted text, click to view]

AddThis Social Bookmark Button