Wednesday, 12 September 2012

Text Concatenation with Select Statement


Written By:- Isha Malhotra (Software Developer)
Email:-malhotra.isha3388@gmail.com.
Note: -if you find this article helpful then kindly leave your comment

For Asp.net Training with C# and Sql Server Click Here


When we need to concatenate the text value with the column names in this case we use + Arithmetic operator.
Check the following example:-
Suppose we want our output like this
“The Employee id of Isha Malhotra is 101”
Note: - Isha(emp_fname), Malhotra(emp_fname) and 101(emp_no)

select 'The Employee id of '+ emp_fname +' ' emp_lname + ' is ' + cast(emp_no as varchar) +'.' from employee;

in this example we used cast operator which is used to cast column in to specific datatype. As emp_no is Int type so first we have to cast it in to varchar so that we can concatenate this column with text.

No comments:

Post a Comment