March 25, 2014 at 3:26 am
Get output of SQL Procedure and assign it to a variable used in WHERE Clause
Later I want to use this variable in my code in the WHERE Clause
Declare @ProjectNo nvarchar(10)
--Now I want to assign it to output of a storedprocedure which returns only 1 value and use it in the below SELECT query.
SELECT ID from TABLEA where Project in (@ProjectNo)
How to do it. How to assign @ProjectNo to output of storedProcedure called 'GetProjNumber'
Please help
March 25, 2014 at 3:30 am
How does the procedure return that? Return code, output variable or resultset?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 25, 2014 at 6:43 am
ms-techie (3/25/2014)
Get output of SQL Procedure and assign it to a variable used in WHERE ClauseLater I want to use this variable in my code in the WHERE Clause
Declare @ProjectNo nvarchar(10)
--Now I want to assign it to output of a storedprocedure which returns only 1 value and use it in the below SELECT query.
SELECT ID from TABLEA where Project in (@ProjectNo)
How to do it. How to assign @ProjectNo to output of storedProcedure called 'GetProjNumber'
Please help
Is @ProjectNo a single value?
March 25, 2014 at 2:30 pm
ms-techie (3/25/2014)
Get output of SQL Procedure and assign it to a variable used in WHERE ClauseLater I want to use this variable in my code in the WHERE Clause
Declare @ProjectNo nvarchar(10)
--Now I want to assign it to output of a storedprocedure which returns only 1 value and use it in the below SELECT query.
SELECT ID from TABLEA where Project in (@ProjectNo)
How to do it. How to assign @ProjectNo to output of storedProcedure called 'GetProjNumber'
Please help
Assuming that your select will always return 1 ID is not safe.
This is what I would write:
CREATE PROCEDURE GetProjNumber ( @ProjectNo int, @ID int OUTPUT)
AS
BEGIN
SELECT @ID = TOP 1 ID from TABLEA where project in (@ProjectNo);
END;
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply