Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 1st, 2007, 08:38 PM
Authorized User
Join Date: Mar 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to miamikk
Default creating variables in a Stored procedure

I would like to know if I can create new variables using existing variables in a stored procedure.

To be clear, in the SP I use, I pass table name. But I need the results from 2 other tables as well.

The tables are named 1996, 1997, 1998.......2007.
If I pass 2005 to SP, I need results from 2005, 2004 & 2003. How do I assign or get 2 new table names (variables) for 2004 & 2003 ??

Part of code:
ALTER Procedure [dbo].[XX](
@TblName1 varchar(20),
@Month varchar(3)

when I pass 2005 to SP, I need
@TblName1 = 2005
@TblName2 = 2004
@TblName3 = 2003

How can assign 2004 & 2003 to variables TblName2 & Tblname3 ??

I really appreciate any help.

  #2 (permalink)  
Old June 4th, 2007, 03:02 AM
Friend of Wrox
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post

IMO, you dont have to use two more variables, You can have a LOOP within the proc running thrice, starting from the VALUE passed to @TblName1 till ( Value - 2 ), thus you can do the same you do for 2005, with other two tables that are required.

Hope that helps/explains.

- Vijay G
Strive for Perfection

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating stored procedure with trigger (HOWTO ..) AzlanAziz SQL Language 0 January 16th, 2007 04:34 AM
Creating Charts Using Stored Procedure srinivasparimi SQL Server 2005 1 August 7th, 2006 06:45 AM
Problem creating Stored Procedure vivekshah SQL Server 2000 4 May 28th, 2006 11:33 PM
creating stored procedure drachx SQL Server 2000 2 October 14th, 2004 08:10 AM
Creating a stored procedure marthaj SQL Server ASP 8 June 10th, 2003 06:08 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.