none
Running stored procedure issues RRS feed

  • Question

  • Hello, 

    I have inherited a stored procedure query problem.  They are trying to run another stored procedure, within a stored procedure already.  

    As they want the results of this stored procedure to be used to update another table via a merge statement.   However it fails on asking me for the parameter in the stored procedure.  Which is already declared in the sql code.  Have I written this in the correct way?  

    SET @qurrie =
    					N'	
    							select *
    							from  ( 'EXEC MNH @_qdate, @_virtual, @_User, NULL')) as qr
    					'					


    Wednesday, September 30, 2015 7:10 PM

Answers

  • I have solved it.
    SET @qurrie =
    					N'	
    							select *
    							from  ( ''EXEC MNH @_qdate, @_virtual, @_User, NULL'')) as qr
    					'			

    I have added in an extra' to the statement.  As it was closing it from the N'.  So by adding it, the stored procedure then was reading it correctly with the parameters. 
    • Marked as answer by cr_banks Wednesday, September 30, 2015 7:55 PM
    Wednesday, September 30, 2015 7:36 PM
  • That code makes no sense. You cannot have an EXEC statement in the FROM clause of a stored procedure.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Wednesday, September 30, 2015 9:59 PM

All replies

  • I have solved it.
    SET @qurrie =
    					N'	
    							select *
    							from  ( ''EXEC MNH @_qdate, @_virtual, @_User, NULL'')) as qr
    					'			

    I have added in an extra' to the statement.  As it was closing it from the N'.  So by adding it, the stored procedure then was reading it correctly with the parameters. 
    • Marked as answer by cr_banks Wednesday, September 30, 2015 7:55 PM
    Wednesday, September 30, 2015 7:36 PM
  • That code makes no sense. You cannot have an EXEC statement in the FROM clause of a stored procedure.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Wednesday, September 30, 2015 9:59 PM