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
 General SQL Server Forums
 New to SQL Server Programming
 How to Tabulate Tables :)

Author  Topic 

dknb
Starting Member

6 Posts

Posted - 2007-02-01 : 22:23:06
Im having problem trying to table this one:

table.Drinks
Type Brand QTY
Coffee Q 2
Coffee Y 3
Coffee L 5
Tea Q 4
Tea Y 1
Tea L NULL

I want the result to be :
Type Brand Q Brand Y Brand L
Coffee 2 3 5
Tea 4 1 Null

Appreciate all your inputs.

Thanks!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-01 : 22:27:47
this is cross tab / pivot query

select Type,
[Brand Q] = sum(case when Brand = 'Q' then QTY else 0 end),
[Brand Y] = sum(case when Brand = 'Y' then QTY else 0 end),
[Brand L] = sum(case when Brand = 'L' then QTY else 0 end)
from Drinks
group by Type




KH

Go to Top of Page

dknb
Starting Member

6 Posts

Posted - 2007-02-02 : 03:27:36
Hi KH

Error ORA-00936 : missing expression

[Brand Q] was highlighted.


Cheers!
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-02 : 03:29:04
because you are using Oracle !

The query is in T-SQL not PL/SQL.


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-02 : 03:30:11
try posting over here http://dbforums.com/forumdisplay.php?f=4



KH

Go to Top of Page

dknb
Starting Member

6 Posts

Posted - 2007-02-04 : 23:10:03
my bad!
Im such a newbie.

Cheers!
Go to Top of Page
   

- Advertisement -