1. This Board Rocks has been moved to a new domain: CarolinaPanthersForum.com

    All member accounts remain the same.

    Most of the content is here, as well. Except that the Preps Forum has been split off to its own board at: http://www.prepsforum.com

    Welcome to the new Carolina Panthers Forum!

    Dismiss Notice

Dynamic Stored Procedure

Discussion in 'Technology Forum' started by chipshot, Nov 13, 2003.

  1. Meow

    Meow Who me?

    Posts:
    1,231
    Likes Received:
    0
    Joined:
    Jan 8, 2003
    You have to put the whole thing in a string variable then execute the string (varchar) variable.


    CREATE PROCEDURE spi_Test
    @vTableName varchar
    AS
    DECLARE @sSQL VarChar(1000)


    Select @sSQL = 'SELECT * FROM ' + @vTableName

    Exec (@sSQL)

    GO
     
  2. chipshot

    chipshot Full Access Member

    Age:
    50
    Posts:
    33,519
    Likes Received:
    0
    Joined:
    Feb 6, 2002
    Location:
    Boise
    Excellent, thank you.
     
  3. Toll Booth Willie

    Toll Booth Willie Welcome to Wusta!

    Age:
    48
    Posts:
    3,441
    Likes Received:
    0
    Joined:
    Jan 8, 2003
    Location:
    Des Moines, IA
    Slick. I figured there HAD to be a way to do it. I couldn't find a way to directly declare tables as variables. I'm sure I will be using this same technique at some point later on.
     

Share This Page