-->

Ads 720 x 90

Return a value from a dynamic sql

For beginners, this is one of the toughest jobs, Here is an example, hope this will help u guys :)

Use Northwind

CREATE PROC TEST(
@DATABASENAME VARCHAR(30),
@COUNTOUT INT OUTPUT
)
AS
BEGIN
DECLARE @v_SQL nVARCHAR(4000)
DECLARE @COUNT INT


SET @V_SQL='SELECT @COUNT=COUNT(*) FROM '+@DATABASENAME+'..Authors'

EXEC SP_EXECUTESQL @V_SQL,N'@COUNT INT OUTPUT',@COUNT OUTPUT
SET @COUNTOUT=@COUNT

RETURN @countout
END

Related Posts

Total Pageviews

Subscribe Our Newsletter