Results 1 to 3 of 3

Thread: Store Procedure

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    32

    Store Procedure

    Hi All,

    I would like to create a store procedure in SQL with input parameter is table's name so that i just change name of table when execute select statement.

    Ex : Create Procedure TestTable @sTable varchar(25)
    as
    Begin
    select * from @sTable
    End

    But this syntax is not correct, Any advise?

    Thanks so much,

    Thanh Nguyen

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Store Procedure

    This is a Database Development issue, not a VB.NET issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Store Procedure

    You cannot have a variable for a table name in a SELECT.

    You can build that SELECT statement into a @SQL varchar() variable - then:

    EXEC (@SQL)

    But dynamic SQL certainly takes away the advantage of a STORED PROCEDURE.

    Why are you doing this?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width