In my Stored Procedure, I am trying to store the result of a SELECT statement inside a variable. This is what I have so far:
DECLARE @process_pk uniqueidentifier
INSERT INTO @process_pk
SELECT process_pk
FROM dbo.Process
WHERE process_id = @process_id
Run Code Online (Sandbox Code Playgroud)
In the above, I'm trying to store the result of the SELECT statement into my variable @process_pk, to be used sometime later in the latter part of my stored procedure. But it doesn't seem to be the correct syntax.
I would like to ask what is the correct way to store SELECT statement results inside a Stored Procedure variable so that it can be used anytime within the stored procedure.
You should use SET
SET @process_PK = (SELECT process_pk
FROM dbo.Process
WHERE process_id = @process_id)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6507 次 |
| 最近记录: |