Click here to Skip to main content
15,915,703 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
VB
DECLARE @CheckQuantity INT
         SET @ParmDefinition = N'@CheckQuantity INT'
         SET @SQL = N'
         SET @CheckQuantity= 12'
                        PRINT @SQL

            EXEC [dbo].sp_executesql @SQL, @ParmDefinition,
            @CheckQuantity=@CheckQuantity;
            PRINT @CheckQuantity


It Should Print 12 but the output is NULL , Please tell me How to SET VALUE For the VAriable declare outside the SQL Text cretaed for dynamic query
Posted

1 solution

you should set the inner (in @SQL) '@CheckQuantity' as OUTPUT. try this:
SQL
DECLARE @CheckQuantity INT
declare @ParmDefinition nvarchar(100)
declare @SQL nvarchar(100)

SET @ParmDefinition = N'@CheckQuantity INT OUTPUT'
SET @SQL = N'SET @CheckQuantity= 12'
PRINT @SQL

EXEC [dbo].sp_executesql @SQL, @ParmDefinition,@CheckQuantity=@CheckQuantity OUTPUT;
PRINT @CheckQuantity


and see here: http://technet.microsoft.com/en-us/library/ms188001.aspx[^]
 
Share this answer
 
Comments
[no name] 14-Feb-14 7:05am    
Thanks
Vedat Ozan Oner 14-Feb-14 8:18am    
you are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900