Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Must declare the scalar variable error

$
0
0

I am getting the error "Must declare the scalar variable "@Result""  when i execute the below query

declare @sql nvarchar(max),

@tablename varchar(200),
@Id int,
@Result int

set @tablename='xyz'
set @id=1

SET @sql = '
SELECT @Result=COUNT( Id ) FROM  ' + @TableName+ ' WHERE RunRegisterKey=' +convert(nvarchar(100),@ID)  

EXEC sys.sp_executesql @sql


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>