Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat two column in a select statement sql server 2005

How to Concat two column in a select statement sql server 2005?

Here is my statement Select FirstName,secondName from Table...

Now i did try concating secondName with FirstName by using

Select FirstName + ' ' + secondName from Table

But some values are NULL in secondName column for some records.. My select statement returns NULL instead of FirstName.. I want to have FirstName if secondName is NULL ..

like image 207
ACP Avatar asked Jan 26 '10 06:01

ACP


People also ask

How do I concatenate two column values in SQL query?

MySQL CONCAT() Function The CONCAT() function adds two or more expressions together. Note: Also look at the CONCAT_WS() function.

Can we use concat in select statement?

We can use a literal in CONCAT Function. A literal is a number, character, or date that includes the SELECT statement.

How do I merge two columns in a single column in SQL?

Procedure. Create two or more queries to select the data you want to merge, then specify the keyword UNION between the queries. In the following figure, the first query selects the department name and number from the Q.ORG table and creates a column that displays the words WAITING FOR WORK.


1 Answers

SELECT FirstName + ISNULL(' ' + SecondName, '') from Table

like image 196
roufamatic Avatar answered Sep 19 '22 16:09

roufamatic