Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Query tricky data problem!

Author  Topic 

jonboy
Starting Member

2 Posts

Posted - 2002-01-09 : 05:46:56
Hi there,
I have a small problem which I need a few hints on.
I am trying to pull out data from a database and modify some of it based on an identifier on the way.

eg
invoicenumber quantity total invoicetype
12312 100 £792 1
12323 50 £45 3
17263 5 £86 2
18256 10 £10 3

With this example data I need to pull out all the values but where the invoice type is 3 I need the quantity and totals to have a minus put in front of them.
I have tried several ideas but my mind is now stuck in a rut!!!
Any ideas!

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-01-09 : 05:54:19
Hi Jonboy

You can do this with the [url="http://www.sqlteam.com/item.asp?ItemID=922"]CASE{/url] statement.

Something like this :



SELECT invoicenumber, quantity,
CASE WHEN invoicetype=3 THEN 0 - quantity ELSE quantity END
as total, invoicetype

FROM

mytable



How is that ?

Damian
Go to Top of Page

jonboy
Starting Member

2 Posts

Posted - 2002-01-09 : 11:34:35
Thanks a lot Merkin, that shot the bitch out of the sky quicksmart!

Go to Top of Page
   

- Advertisement -