Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server, how to merge two columns into one column?

I have a SQL query

SELECT TABLE_SCHEMA + TABLE_NAME AS ColumnZ 
FROM information_schema.tables

I want the result should be table_Schema.table_name.

help me please!!

like image 774
user3807363 Avatar asked Aug 08 '14 16:08

user3807363


4 Answers

Try this:

SELECT TABLE_SCHEMA + '.' + TABLE_NAME AS ColumnZ 
FROM information_schema.tables
like image 60
Adrian Avatar answered Sep 23 '22 23:09

Adrian


This code work for you try this....

SELECT Title,
FirstName,
lastName, 
ISNULL(Title,'') + ' ' + ISNULL(FirstName,'') + ' ' + ISNULL(LastName,'') as FullName 
FROM Customer
like image 23
Sunil Acharya Avatar answered Sep 20 '22 23:09

Sunil Acharya


SELECT CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) AS ColumnZ FROM information_schema.tables
like image 25
Dai Avatar answered Sep 20 '22 23:09

Dai


From SQL Server 2017 onwards, there is CONCAT_WS operator, to concatenate with separators.

SELECT CONCAT_WS('.', TABLE_SCHEMA ,TABLE_NAME) AS ColumnZ 
FROM information_schema.tables
like image 30
Venkataraman R Avatar answered Sep 23 '22 23:09

Venkataraman R