Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SET output param from SQL string?

Author  Topic 

tech1
Starting Member

49 Posts

Posted - 2012-03-27 : 04:47:50
if I have a sproc which has an OUTPUT param:

@myParam BIT

and I execute a query I create within the SPROC and use SP_EXECUTESQL to execute that query, how can I, within that string query, set @myParam value?

is it possible?

rajarajan
Starting Member

48 Posts

Posted - 2012-03-27 : 04:57:11
DECLARE @SQLString nvarchar(500);
DECLARE @ParmDefinition nvarchar(500);
DECLARE @CountSQLQuery varchar(30);

SET @SQLString = N'SELECT @result = COUNT(*) FROM Tabel ';
SET @ParmDefinition = N'@result varchar(30) OUTPUT';

EXECUTE sp_executesql @SQLString, @ParmDefinition, @result=@CountSQLQuery OUTPUT;

-- print @CountSQLQuery
SELECT CAST(@CountSQLQuery as int);
Go to Top of Page
   

- Advertisement -