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
 A Shorter Script.

Author  Topic 

Deon Smit
Starting Member

47 Posts

Posted - 2008-11-24 : 08:23:54
Hi. This is my script. Is there any way that I can Shorten this.

My Range is always from 301 to 341

SELECT *
FROM (SELECT T$ITEM,
sum(decode(T$CWAR,301,T$STOC,0)) "301",
sum(decode(T$CWAR,302,T$STOC,0)) "302",
sum(decode(T$CWAR,303,T$STOC,0)) "303",
sum(decode(T$CWAR,304,T$STOC,0)) "304",
sum(decode(T$CWAR,305,T$STOC,0)) "305",
sum(decode(T$CWAR,306,T$STOC,0)) "306",
sum(decode(T$CWAR,307,T$STOC,0)) "307",
sum(decode(T$CWAR,308,T$STOC,0)) "308",
sum(decode(T$CWAR,309,T$STOC,0)) "309",
sum(decode(T$CWAR,310,T$STOC,0)) "310",
sum(decode(T$CWAR,311,T$STOC,0)) "311",
sum(decode(T$CWAR,312,T$STOC,0)) "312",
sum(decode(T$CWAR,313,T$STOC,0)) "313",
sum(decode(T$CWAR,314,T$STOC,0)) "314",
sum(decode(T$CWAR,315,T$STOC,0)) "315",
sum(decode(T$CWAR,316,T$STOC,0)) "316",
sum(decode(T$CWAR,317,T$STOC,0)) "317",
sum(decode(T$CWAR,318,T$STOC,0)) "318",
sum(decode(T$CWAR,319,T$STOC,0)) "319",
sum(decode(T$CWAR,320,T$STOC,0)) "320",
sum(decode(T$CWAR,321,T$STOC,0)) "321",
sum(decode(T$CWAR,322,T$STOC,0)) "322",
sum(decode(T$CWAR,323,T$STOC,0)) "323",
sum(decode(T$CWAR,324,T$STOC,0)) "324",
sum(decode(T$CWAR,325,T$STOC,0)) "325",
sum(decode(T$CWAR,326,T$STOC,0)) "326",
sum(decode(T$CWAR,327,T$STOC,0)) "327",
sum(decode(T$CWAR,328,T$STOC,0)) "328",
sum(decode(T$CWAR,329,T$STOC,0)) "329",
sum(decode(T$CWAR,330,T$STOC,0)) "330",
sum(decode(T$CWAR,331,T$STOC,0)) "331",
sum(decode(T$CWAR,332,T$STOC,0)) "332",
sum(decode(T$CWAR,333,T$STOC,0)) "333",
sum(decode(T$CWAR,334,T$STOC,0)) "334",
sum(decode(T$CWAR,335,T$STOC,0)) "335",
sum(decode(T$CWAR,336,T$STOC,0)) "336",
sum(decode(T$CWAR,337,T$STOC,0)) "337",
sum(decode(T$CWAR,338,T$STOC,0)) "338",
sum(decode(T$CWAR,339,T$STOC,0)) "339",
sum(decode(T$CWAR,340,T$STOC,0)) "340",
sum(decode(T$CWAR,341,T$STOC,0)) "341",
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-24 : 08:37:47
what does decode do? is it a udf?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-24 : 08:48:40
ORACLE function.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 08:52:24
Aha...then you must be posting this in oracle forums like www.dbforums.com

this is MS SQL Server forum
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-24 : 08:56:16
DECODE is a "CASE WHEN ELSE END".



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -