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)
 adding preyear column besides year column

Author  Topic 

yingchai
Starting Member

33 Posts

Posted - 2011-06-07 : 02:44:22
Hi, I need your expertise on this issue. Basically the reason to do this is to calculate YTD values.


For example, I have the following period table

year period quarter
--------------------------
2011 01 Q1
2011 02 Q1
2011 03 Q1


Based on the example above, I intend to get the following result set:

year period quarter preyear
--------------------------
2011 01 Q1 2010
2011 02 Q1 2010
2011 03 Q1 2010


Any help you can provide with be greatly appreciated.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-06-07 : 03:40:35
select year, period, quarter, year - 1 as preyear from yourtablenamehere



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

yingchai
Starting Member

33 Posts

Posted - 2011-06-07 : 03:59:15
Thanks Peso!
Go to Top of Page
   

- Advertisement -