SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 within select query using if condition base on mth
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

540 Posts

Posted - 02/07/2013 :  07:56:12  Show Profile  Reply with Quote
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.

Edited by - cplusplus on 02/07/2013 07:56:47

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/07/2013 :  09:26:23  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000