How to get OUTPUT from “sp_ExecuteSQL” stored procedure


A simple example of to get OUTPUT from sp_ExecuteSQL store procedure.

USE [AdventureWorks]
GO

DECLARE @TableName      VARCHAR(100)
DECLARE @varSQL         NVARCHAR(4000)
DECLARE @iCount         INT

SET @TableName = 'Person.Address'
SET @varSQL = 'SELECT TOP 1 @iCountOut = rows FROM sys.partitions where object_id = ' + CAST(object_id(@TableName) AS VARCHAR(100))

EXECUTE sp_ExecuteSQL @varSQL, N'@iCountOut INT OUTPUT', @iCountOut = @iCount OUTPUT

SELECT @iCount
GO
Advertisements

One thought on “How to get OUTPUT from “sp_ExecuteSQL” stored procedure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s