Saturday, 12 March 2011

How To Fetch Next 10 Years From Database


DECLARE    @yearFrom SMALLINT,@yearTo SMALLINT,@lenthOfyear SMALLINT
set @lenthOfyear=10
SELECT @yearFrom =year( getdate())set @YearTo = @yearFrom+@lenthOfyear SELECT
CAST(temp.Number + @yearFrom AS CHAR(4)) as [Year]FROM(SELECT    Number
FROM    master..spt_values
WHERE    Type = 'P'AND Number <= @YearTo - @YearFrom) AS temp



No comments:

Post a Comment

Get all non-clustered indexes

DECLARE cIX CURSOR FOR     SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID         FROM Sys.Indexes SI             ...