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

Sql Server 6.5 Case Statement, I hope this isnt a repost

Status
Not open for further replies.

yogeshc

Programmer
Jan 8, 2001
4
US
Hello,
I posted this about an hour ago but I haven't see it come up on the board so I am reposting in case i made a mistake. I apologize in advance if I am reposting. Here goes

I have a table that contains 3 fields. Type (a type of labor performed), amount (dollar value), and invoice number. On one invoice number there can be different labor performed. For example invoice x could have 4 entries

type amount invoice
----- ----- -------
k 10 1
u 20 1
G 30 1
t 40 1

I want to do a query to return different types into different colums. Would the code below work in SQL 6.5? If not, how can I add CASE logic or IF... ELSE logic into a sql 6.5 query. Thanks a whole lot. I would try this out but i am at home and cant access the server.

case
when ((type="k") or (type="u")) THEN
approved_amount as KIT

when ((type="g") or (type="t")) THEN
approved_amount as glass_approved_amount
END
 

One way:

Code:
Select 
Kit = 
case
   when ((type="k") or (type="u")) THEN approved_amount
   else 0
end,
glass_approved_amount =
case 
   when ((type="g") or (type="t")) THEN approved_amount
   else 0 
END

This also assumes your other logic is set to handle the zeros in the non-used column.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top