Groups | Blog | Home
all groups > sql server mseq > march 2006 >

sql server mseq : Help with a query please


RobA
3/12/2006 3:17:27 AM
I have been strugling with for hours -
I have a table with the following columns
UID(decimal) | SD(bit) | MB(bit) | TS(bit) | Total(Decimal)

I want to run a query which will return
UID, Total if SD is True AND
UID, Total if MB is True AND
UID, Total if TS is True


UID is the userID so there would be a WHERE statement
ORDERED BY Total Descending

Many thanks in advance
--
Many thanks,
Hugo Kornelis
3/12/2006 10:56:38 PM
[quoted text, click to view]

Hi Rob,

It's hard to tell exactly what you need from this description. If the
query below is not what you need, then please read www.aspfaq.com/5006
to find a better way to describe your problem.

SELECT UID,
SUM(CASE WHEN SD = CAST(1 AS bit) THEN Total ELSE 0 END),
SUM(CASE WHEN MB = CAST(1 AS bit) THEN Total ELSE 0 END),
SUM(CASE WHEN TS = CAST(1 AS bit) THEN Total ELSE 0 END)
FROM YourTable
GROUP BY UID

--
AddThis Social Bookmark Button