简体   繁体   中英

how to pass the result of SELECT statement to Stored Proc

what's the proper way to write it? Thx

  SELECT 
      [JobId] as jobid


  FROM [v_Jobs]
  WHERE jobreference =177127

EXEC    [dbo].[s_someStoredProc] @JobID = jobid

You need to store that value in a variable:

DECLARE @MyJobID INT

SELECT 
      @MyJobID = [JobId]
FROM [v_Jobs]
WHERE jobreference =177127

EXEC  [dbo].[s_someStoredProc] @JobID = @MyJobID

If you're using MS SQL Server then you can do this very easily in Management studio. Rigth click on a stored procedure -> Execute -> Fill in the fields -> Management Studio generates a Query for you.

You can see how that works or just use the generated query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM