Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Posts
    1

    Unanswered: sp_executesql problem

    I have a stored procedure and I am using sp_executesql stmt to execute sql stmts with parameters. I need to use sp_executesql stmt 2 times with different sql and different parameters. It is giving me an error when executing the sp_executesql stmt second time. It is still looking for the same sql that is been set at first time. How to tell it to use different sql and params?
    Thanks in advance,
    mc

  2. #2
    Join Date
    Feb 2003
    Location
    Montreal, Canada
    Posts
    117

    Re: sp_executesql problem

    Build the sql statement to execute dynamically and then pass it to sp_executesql proc. For instance:

    -------------------------------------
    declare @strSQL varchar(1000)
    set @strSQL = 'select * from MyTable where Field01=' @procedure_input_param
    sp_executesql @strSQL
    -------------------------------------




    Originally posted by mchenna
    I have a stored procedure and I am using sp_executesql stmt to execute sql stmts with parameters. I need to use sp_executesql stmt 2 times with different sql and different parameters. It is giving me an error when executing the sp_executesql stmt second time. It is still looking for the same sql that is been set at first time. How to tell it to use different sql and params?
    Thanks in advance,
    mc
    Steve

  3. #3
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    Also refer to BOOKS ONLINE for SP_EXECUTESQL topic.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

Posting Permissions

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