Thursday, 19 September 2013

Conversion failed while converting nvarchar value to datatype int

Conversion failed while converting nvarchar value to datatype int

I want to get the values of @sql to p. But while conversion it says that
"Conversion failed when converting the nvarchar value 'select sum(stock)
from[Hard disk]' to data type int."
declare @tname varchar(10);
declare @p int
declare @i int
declare @sql nvarchar(max);
set @tname = 'Hard disk';
set @sql = 'select sum(stock) from' + '[' + @tname + ']'
exec (@sql)
print @sql
select @p = convert(int,@sql)
print @p
What i want is to assign the result of the query @SQL in integer variable
@p..

No comments:

Post a Comment