Solved

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

Posted on 2011-03-02
2
203 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

839 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