?
Solved

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

Posted on 2011-03-02
2
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 500 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

718 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