468,527 Members | 2,070 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,527 developers. It's quick & easy.

Dependent CASE function of another CASE function in a SELECT statement

22
I would like to know the way that I can write a CASE function in a select statement that uses another variable that is created in the same SELECT statement using another CASE function. This is exacly what I am trying to do but obviusly gives me an error because is incorrect:

SELECT
CSV_SRV_QTY,
NET_PAID,
case when NET_PAID=0 THEN 0 ELSE CSV_SRV_QTY END AS ADJUNITS1,
CASE WHEN NET_PAID<0 AND ADJUNITS1>0 THEN -(ADJUNITS1) ELSE ADJUNITS1 END AS ADJUNITS2
FROM
CSV_MSTR
;

ADJUNITS1 runs fine but when add the second variable (ADJUNITS2) it produces an error.
Mar 14 '08 #1
1 1982
EORTIZ
22
NEVER MIND, HERE IS THE ANSWER. MAYBE SOMEONE IS INTERESTED
Expand|Select|Wrap|Line Numbers
  1. select units, total_paid, adjunits1,
  2. CASE WHEN total_paid<0 AND ADJUNITS1>0 THEN -(ADJUNITS1) ELSE ADJUNITS1 END AS ADJUNITS2 from
  3. (SELECT 
  4.     CSV_MSTR.CSV_SRV_QTY as units, 
  5.     CSV_MSTR.NET_PAID as total_paid,
  6.     case when NET_PAID=0 THEN 0 ELSE CSV_SRV_QTY END AS ADJUNITS1
  7.  
  8. FROM 
  9.     CSV_MSTR )
Mar 14 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by christian | last post: by
4 posts views Thread by Terencetrent | last post: by
7 posts views Thread by Lauren Quantrell | last post: by
1 post views Thread by Hifni Shahzard | last post: by
8 posts views Thread by | last post: by
1 post views Thread by microsoft.public.dotnet.languages.vb | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.