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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I ? STORED PROCEDURE

Status
Not open for further replies.

spDavCom

Programmer
Feb 16, 2003
13
US

CHALLENGE:

I have a column in a sql db that is filled with credit and debit values or + and - money values.

QUESTION:

How do I return the sum total of the positives and the sum total of the negatives from one stored procedure

NOTE:

I can do this if I write 2 stored procedures, but how do I do it in one?

Any input or syntax is much appreciated.



 
Assuming a table named tableWithCreditDebit having a column named creditDebit.

create procedure sb_01
as
select sum(case when creditDebit < 0 then creditDebit else 0 end) as debit,
sum(case when creditDebit > 0 then creditDebit else 0 end) as credit from tableWithCreditDebit
 
Thank you! very much! Your syntax worked great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top