Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate a Varchar and int [duplicate]

Tags:

sql

sql-server

I need to Concatenate a Varchar and int in T-SQL , !

like image 869
Sudantha Avatar asked Feb 05 '11 05:02

Sudantha


People also ask

How do you concatenate int and varchar columns in SQL?

In the earlier version of SQL Server, we usually use CONVERT function to convert int into varchar and then concatenate it. Given below is the script. Solution 2: In this solution, we will use CONCAT function (a newly shipped function in SQL Server 2012) to convert int into varchar then concatenate it.

Can we concatenate string and integer in SQL?

To concatenate we can use + sign but this works only with String values. So if we have any Integer value/s we have to convert them to String first. We can use Cast or Convert function to convert Integer value to string.

How do I concatenate two data types in SQL?

Solution. TSQL provides 2 ways to concatenate data, the + sign and the new CONCAT() function. This tip will cover the differences in the two, so you can achieve the expected behavior in your code. The way most us are used to concatenating data together is using the + sign.


2 Answers

SELECT ('VarValue' + CAST(32 AS VARCHAR))
like image 71
used2could Avatar answered Oct 13 '22 22:10

used2could


varcharName + cast(intName as varchar) as full_name

Should do it

like image 41
Ralph Avatar answered Oct 13 '22 22:10

Ralph