SQL Server - how to combine two columns in to one using query.

Asked By aman on 07-Mar-12 06:22 AM
hi all,

i have a table which have fields like firstName and Last Name respectively

i want to display the name like FirstName,LastName

for eg:- if First is Aman and LastName is Khan
than i want to display as Aman,Khan

Web Star replied to aman on 07-Mar-12 06:26 AM
Just add two column in query to get full name as your format as follows

Select  FirstName + '', '' + LastName AS FullName From Tblname

hope this helps you
dipa ahuja replied to aman on 07-Mar-12 06:33 AM
<asp:Label ID="Label1" runat="server" Text="Welcom ,">
  <%# Eval("fname") + " " + Eval("lname") %>'
<asp:Label ID="Label1" runat="server" Text="Welcom ,">
  <%# Eval("gender") %>'
void getReuslt()
    string ConnString = "ConnectionString";
    SqlDataAdapter da = new SqlDataAdapter("SELECT gender, (fname+ ' ' + lname)  as name from people", ConnString);
    DataTable dt = new DataTable();
    GridView1.DataSource = dt;
Somesh Yadav replied to aman on 07-Mar-12 06:37 AM
I have two columns `lastname` and `organization`. If one is filled then the other one is always empty. A normal SELECT * FROM table ORDER BY organization,lastname would list all the organizations first and then the lastnames second, but I wanted to intermix them, so I did this:
SELECT * FROM table ORDER BY CONCAT(organization,lastname)

This will combine the two columns for the ORDER BY without actually creating a new column.
kalpana aparnathi replied to aman on 07-Mar-12 06:38 AM

Try  this way:

select First_name + ',' + Last_Name AS Full_Name
 From tablename