Solved

Specific years 1998 to current years into a temp table SQL Server

Posted on 2011-03-02
2
204 Views
Last Modified: 2012-05-11
I want to create a stored  procedure that will give me the years from 1998 till the current year and put the values into a temp table.  This should be easy but am not getting the right thought process going. please help
0
Comment
Question by:etan08
2 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 125 total points
ID: 35017344
If you're just trying to put "1998", "1999", ..., "2011" into a temp table, but want it dynamic, its going to be easiest to just do this:

declare @yr int
select @yr = 1998
while @yr <= (select year(getdate()))
begin
    insert into <tbl> select @yr
    select @yr = @yr + 1
end
0
 

Author Closing Comment

by:etan08
ID: 35017551
Thanks
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question