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
 breaking data from one column to multiple

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2010-01-12 : 13:46:46
I have this query

Select dtmValidThru, datediff(mm, getdate(), dtmValidThru) Months
From RES_Entity.dbo.tblEntityName
Where dtmValidThru < getdate()

simple enough I need to break the data in the column "Months" so that when the number is < 13 its a column, when > 12 but < 25 its a column, > but less than 37, and 37+

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-12 : 13:51:14
do you mean this?

Select dtmValidThru,
datediff(mm, getdate(), dtmValidThru) <13 then datediff(mm, getdate(), dtmValidThru) else null end as col1,
datediff(mm, getdate(), dtmValidThru) > 12 and datediff(mm, getdate(), dtmValidThru) < 25 then datediff(mm, getdate(), dtmValidThru) else null end as col2,
datediff(mm, getdate(), dtmValidThru) >25 and datediff(mm, getdate(), dtmValidThru) <37 then datediff(mm, getdate(), dtmValidThru) else null end as col3,
...
From RES_Entity.dbo.tblEntityName
Where dtmValidThru < getdate()
Go to Top of Page
   

- Advertisement -