Tuesday, December 11, 2012

Concatenate integer values in Sql Server

In the below example we need to return 12 as the result not 3 which is the addition of the two numbers. So we need concatenation, we can not concatenate integer values unless they are converted into varchar.

declare @no1 int
declare @no2 int
declare @result varchar(10)

set @no1=1
set @no2=2
set @result=CONVERT(varchar,@no1)+CONVERT(varchar,@no2)

select @result as 'Concat_Result'

CONVERT function will convert those integer values into varchar type and perform the concatenation.

No comments:
Write comments
Recommended Posts × +