Concatenating Columns in query
-
Hi, i am using sql server 2005 and i am writing one query to concatename 3 column values.. SELECT distinct(P.firstname + ' ' + P.middlename + ' ' + P.lastname) AS UserName ,P.Id as UserId,G.Id,G.Fkgroupid FROM c_Groupmember G,c_Person P where P.Id=G.FKUserid and G.FKgroupId=" + Id + " and P.Status=0 order by P.firstName asc it will disply the username if first name and lastname is there .if there is only firstname .then i won't display any value?.... what is the solution for this ?.in query itself i need to get all the usernames. with regards anu
-
Hi, i am using sql server 2005 and i am writing one query to concatename 3 column values.. SELECT distinct(P.firstname + ' ' + P.middlename + ' ' + P.lastname) AS UserName ,P.Id as UserId,G.Id,G.Fkgroupid FROM c_Groupmember G,c_Person P where P.Id=G.FKUserid and G.FKgroupId=" + Id + " and P.Status=0 order by P.firstName asc it will disply the username if first name and lastname is there .if there is only firstname .then i won't display any value?.... what is the solution for this ?.in query itself i need to get all the usernames. with regards anu
Rewrite query as SELECT distinct( COALESEC(P.firstname,P.firstname,'') + ' ' + COALESEC(P.middlename,P.middlename,'') + ' ' + COALESEC(P.lastname,P.lastname,'')) AS UserName ,P.Id as UserId,G.Id,G.Fkgroupid FROM c_Groupmember G,c_Person P where P.Id=G.FKUserid and G.FKgroupId=" + Id + " and P.Status=0 order by P.firstName asc for more information see COALESCE function documentation.
Intelligence is measured by common sense not by how many scholarly books you read.
-
Rewrite query as SELECT distinct( COALESEC(P.firstname,P.firstname,'') + ' ' + COALESEC(P.middlename,P.middlename,'') + ' ' + COALESEC(P.lastname,P.lastname,'')) AS UserName ,P.Id as UserId,G.Id,G.Fkgroupid FROM c_Groupmember G,c_Person P where P.Id=G.FKUserid and G.FKgroupId=" + Id + " and P.Status=0 order by P.firstName asc for more information see COALESCE function documentation.
Intelligence is measured by common sense not by how many scholarly books you read.
-
it is showing an error Msg 195, Level 15, State 10, Line 1 'COALESEC' is not a recognized built-in function name.
-
Hi, i am using sql server 2005 and i am writing one query to concatename 3 column values.. SELECT distinct(P.firstname + ' ' + P.middlename + ' ' + P.lastname) AS UserName ,P.Id as UserId,G.Id,G.Fkgroupid FROM c_Groupmember G,c_Person P where P.Id=G.FKUserid and G.FKgroupId=" + Id + " and P.Status=0 order by P.firstName asc it will disply the username if first name and lastname is there .if there is only firstname .then i won't display any value?.... what is the solution for this ?.in query itself i need to get all the usernames. with regards anu
-
Hi, i am using sql server 2005 and i am writing one query to concatename 3 column values.. SELECT distinct(P.firstname + ' ' + P.middlename + ' ' + P.lastname) AS UserName ,P.Id as UserId,G.Id,G.Fkgroupid FROM c_Groupmember G,c_Person P where P.Id=G.FKUserid and G.FKgroupId=" + Id + " and P.Status=0 order by P.firstName asc it will disply the username if first name and lastname is there .if there is only firstname .then i won't display any value?.... what is the solution for this ?.in query itself i need to get all the usernames. with regards anu