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

select question

Status
Not open for further replies.

ktucci

Programmer
Apr 23, 2001
146
US
soppose i have this query:

select field1, field2, amount
from anytable

and the amount column shows amounts consisting of both negatives and positives. how could a display 2 columns for amounts being all of the negatives and the other with all of the positives

any help will be greatly appreciated

keith
 
Use a Case statement.

select
field1,
field2,
Case when isnull(amount,0) > 0 Then isnull(amount,0) Else 0 End As PosAmt,
Case when isnull(amount,0) < 0 Then isnull(amount,0) Else 0 End As NegAmt
from anytable

I included isnull to handle any null values. Your query may not require it. Terry

The reason why worry kills more people than work is that more people worry than work. - Robert Frost
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top