sql server - Cant Print Int after varchar -


why can't print deptid integer?

alter proc spgetnamebyid     @id int,     @name varchar(50) output,     @gender varchar (50) output,     @deptid int output begin     select          @name = name, @gender = gender ,          @deptid = deptid               tblemployee               id = @id end  declare @getname varchar(50), @getgender varchar(50), @getdeptid int  execute spgetnamebyid 1, @getname out, @getgender out, @getdeptid out  print 'name of employee ' + @getname + ' gender ' + @getgender + 'dept id ' + @getdeptid 

my error

msg 245, level 16, state 1, line 3
conversion failed when converting varchar value 'name of employee john gender maledept id ' data type int.

the @getdeptid integer value, need convert varchar before concatenating string

print 'name of employee ' + @getname + ' gender '                    + @getgender + 'dept id ' + cast(@getdeptid varchar(10)) 

reason

when not explicitly convert int value varchar before concatenating , int being higher prescience data type, sql server tries convert string int , fails, hence error message.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -