Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent Case query!!!!

Status
Not open for further replies.

munchen

Technical User
Aug 24, 2004
306
GB
I am using two case statements in a simple select statement like so:

CASE WHEN tblD.Type = 'CL'THEN
SUM(tblD.Amount) END AS SumOfAmount,
CASE WHEN tblD.Type = 'CP'THEN
SUM(tblD.Amount) END AS SumOfPayments

However what I need to do in the 2nd case statement is to only do the sum when the result of the 1st case statement is <> 0.

So the 2nd case statement would become something like this:

CASE WHEN tblD.Type = 'CP'AND
SumOfAmount <> 0 THEN
SUM(tblD.Amount) END AS SumOfPayments

Is this possible?


 
hmm, sorry -
it looks like you have something else in mind, for which a different example is needed:
Code:
declare @rez1 varchar(1000)
select @rez1 = case when (1 > 2 OR 3 < 4) then '1'
when 2 > 1 then '2'
end

select @rez1

declare @rez2 varchar(1000)
select @rez2 = case when @rez1 = '1' then '1!'
when @rez1 = '2' then '2!'
end

select @rez2

may be it is also possible to do this with nested query instead of using variables?

------------------------
 
CASE WHEN tblD.Type = 'CP'AND
SUM(tblD.Amount) <> 0 THEN
SUM(tblD.Amount) END AS SumOfPayments


r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top