11

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!!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3807363
  • 143
  • 1
  • 1
  • 5

4 Answers4

19

Try this:

SELECT TABLE_SCHEMA + '.' + TABLE_NAME AS ColumnZ 
FROM information_schema.tables
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Adrian
  • 6,013
  • 10
  • 47
  • 68
6

This code work for you try this....

SELECT Title,
FirstName,
lastName, 
ISNULL(Title,'') + ' ' + ISNULL(FirstName,'') + ' ' + ISNULL(LastName,'') as FullName 
FROM Customer
Sunil Acharya
  • 1,153
  • 5
  • 22
  • 39
5
SELECT CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) AS ColumnZ FROM information_schema.tables
Dai
  • 1,510
  • 1
  • 11
  • 12
  • 5
    Watch out: `CONCAT` is a **new feature** in SQL Server **2012** and thus might not be available to the person asking – marc_s Aug 08 '14 at 16:17
  • 2
    @marc_s I did not know this, it will be useful if I ever have to work with old MSSQL versions, thanks. – Dai Aug 08 '14 at 16:22
  • 5
    Being a new feature doesn't make the answer worthy of a downvote, in my opinion. – Gordon Linoff Aug 08 '14 at 16:22
  • 1
    @GordonLinoff: just to be absolutely clear - it wasn't my downvote; I agree with you - it's a new feature, but it's correct - for that newer version of SQL Server. No downvote warranted ... – marc_s Aug 08 '14 at 16:23
2

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
Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
  • 1
    This is great for handling nulls, where you don't want the extra separators, and can do the same for empty strings in a column if it is wrapped in NULLIF(). – Mark E. Nov 25 '22 at 19:57