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
 Rows as Columns But so Many

Author  Topic 

Deon Smit
Starting Member

47 Posts

Posted - 2008-11-20 : 01:32:20
Hi

I have figured out how to select Rows as columns per item as rows and stock per warehouse.
But the thing is. I have 45 warehouses starting at 301, 302 ,303 ......

How can I modify my script so that I don't have to do this 45 times. I only dit it 7 times in my scripts. Please help.

SELECT *
FROM (SELECT T$ITEM,
sum(decode(T$CWAR,301,T$STOC,0)) WAR301,
sum(decode(T$CWAR,302,T$STOC,0)) WAR302,
sum(decode(T$CWAR,303,T$STOC,0)) WAR303,
sum(decode(T$CWAR,304,T$STOC,0)) WAR304,
sum(decode(T$CWAR,305,T$STOC,0)) WAR305,
sum(decode(T$CWAR,306,T$STOC,0)) WAR306,
sum(decode(T$CWAR,307,T$STOC,0)) WAR307,
sum(decode(T$CWAR,308,T$STOC,0)) WAR308,
sum(T$STOC) TOTAL

FROM baandb.ttdinv001700
GROUP BY T$ITEM)
ORDER BY 1;

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-20 : 01:51:04
is this sql server syntax? is decode a udf?
if not,i dont think you're not using ms sql. if not, post this in some other forums. this is ms sql server forum
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-20 : 04:07:01
Post your question at www.orafaq.com


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -