pass variable for row

  • I can't figure out how to pass a parameter to a stored procedure to select a specific row, like

    CREATE PROCEDURE GP @ID NVARCHAR(100),

    @language NVARCHAR(100)

    AS

    SELECT @language FROM lkptable WHERE ID = @ID

    GO

    When I execute this procedure with

    GP 2,English

    I get the word 'English' back, instead of the content of row 'English'

    Anyone have any ideas?

  • You need to specify the @language parameter as being OUTPUT. In turn, when calling the procedure you have to specify OUTPUT again. No need to provide any value for language when calling, because your procedure only set, but does not use, the variable.

    Eg.

     CREATE PROCEDURE GP @ID NVARCHAR(100),
    
    @language NVARCHAR(100) OUTPUT
    AS

    SELECT @language FROM lkptable WHERE ID = @ID
    GO


    DECLARE @Lang NVARCHAR(100)
    EXECUTE GP 'GP 2', @language= @Lang OUTPUT

    Cheers,

    - Mark


    Cheers,
    - Mark

  • Ahem, I might be missing something, but when you do a

    SELECT @language FROM lkptable WHERE ID = @ID

    and assign @language = 'English' it seems pretty logical to me that you get 'English' back.

    Is ID a unique identifier for the row?

    If so, why not only pass Id to your proc and do

    SELECT * FROM lkptable WHERE ID = @ID

    This should give the whole content of the row

    If there can be the same ID multiple times and you need to select the 'English' one, what about

    SELECT * FROM lkptable WHERE ID = @ID AND language =@language

    HTH

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

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