pass a table as a sproc parameter

  • Hi folks,

    I would like to pass a table into my sproc as a parameter.No joy, I know that I can use UDF's that return a table, but is there any way that I can achieve the underneath?

    eg.

    CREATE PROCEDURE [dbo].[spSelectFromLookup]

    (

    @lookupTable TABLE

    )

    AS

    SELECT *

    FROM @lookupTable

    GO

    when I try to save this sproc, I get an error:

    "Must declare the variable, @lookupTable"

    Can anyone help?

    cheers,

    yogiberr

  • You can create and populate a temp table then access it from within the SP.

    Cursors never.

    DTS - only when needed and never to control.


    Cursors never.
    DTS - only when needed and never to control.

  • try using dynamic sql in the SP e.g.

    EXEC ("Select * from " + @msLookUptable)

  • Nice one,

    thanks for the replies folks.

    yogi

  • I like this, What's the final product (SQL Statement) look like?

    Isaiah


    -Isaiah

  • Hi, sorry for late reply.

    i eneded up buiding the sql as text, as opposed to a stored proc.

    So, I did something like:

    dim sSql as string

    sSql ="SELECT * FROM " &tableName

    and i then passed this variable to the database as commandtext.maybe not the best way, but that's what i did.

    hth

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply