In table, 2 fields ID as int and Number as small int and i want to concatenate the two fields and display as string
eg: ID = 101 and Number = 9
output : 101.9
Dot to be added in between ID and Number? How to query in SQL?
Concatenates two strings and sets the string to the result of the operation. For example, if a variable @x equals 'Adventure', then @x += 'Works' takes the original value of @x, adds 'Works' to the string, and sets @x to that new value 'AdventureWorks'.
To concatenate a String and some integer values, you need to use the + operator. Let's say the following is the string. String str = "Demo Text"; Now, we will concatenate integer values.
You can CAST your integer field to varchar and then concatenate them as you want.
DECLARE @ID INT
DECLARE @Number INT
SET @ID = 101
SET @Number = 9
SELECT CAST(@ID AS VARCHAR(10) ) +'.'+ CAST(@Number AS VARCHAR(10) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With