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 2008 Forums
 Transact-SQL (2008)
 within select query using if condition base on mth

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-02-07 : 07:56:12
I want to use below select query with if condition or decode, is it possible:

SELECT  'ACTUAL' || '2013' AS DataSet,         

Company AS Facility,

'99000004' AS Sub_Account,

'S' AS Account_Type,

SUM((CR_Units_01 + DB_Units_01)/177.14) AS Month1,

--I want to use the below line script if sysdate month is greater than 2 else '0' as month2,

SUM((CR_Units_01 + DB_Units_01 + CR_Units_02 + DB_Units_02)/177.14) AS Month2,

--I want to use the below line script if sysdate month is greater than 3 else '0' as month3,

SUM((CR_Units_01 + DB_Units_01 + CR_Units_02 + DB_Units_02 + CR_Units_03 + DB_Units_03)/177.14) AS Month3,


I want to use this logic till month 12.
Thank you very much for the helpful info.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-07 : 09:26:23
doesnt look like T-SQL to me as || is not concatenation operator in t-sql. I guess its Oracle

In T-SQL, your requirement can be obtained by applying UNPIVOT

For Oracle specific syntax, please post in some Oracle related forums like www.orafaq.com

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -