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

sp_executesql dynamic sql

$
0
0

 Hello,

 I am new to sql server . I  try this following code but this gives an error like

Conversion failed when converting the nvarchar value 'update emp1 set gender='m' where id=' to data type int."

Please can anybody tell how should I avoid this 

I have emp1 table in which the gender column is of char and id is of int type 

Declare @v1 char,@v2 int,@str nvarchar(max)

set @v1='m'
set @v2=1
        Set @str=N'update emp1 set gender='''+@v1+''' where id='+@v2+''
exec  sp_executesql @str
                    
                    


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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