I have a table with a column period. the value in this column will be like this, 201101, 201102, 201103,etc, 201112, 201201 etc If i give a number n and any period p, then it has to retrieve a period = p – n. That means it has to go n period before. Please help me how to do this. Im using SQL Server 2008. Period column is integer type.
Share
If I understand what you need, try this:
My idea is first to take n periods backward (with subquery) and then take (with main query) the last record from subquery.
If you want a period (not only one record) you could use: