Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

Aged Yak Warrior

567 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

Very Important crosS Applying yaK Herder

52326 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

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next 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.07 seconds. Powered By: Snitz Forums 2000