Solved

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

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

710 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