Give a header to each sql query request

I have a sql script that is nothing more than a combination of several Select queries, such as:

Select * from ABC Select * from CD Select * from EN 

Now when I execute it, I use for output, for example

 <output 1> <output 2> <output 3> 

Requirement: I need some heading to be displayed for each of the results.

To be more clear, I want the output to look like this:

 Heading for Output of SQL query 1 output 1 Heading for Output of SQL query 2 output 2 Heading for Output of SQL query 3 output 3 

Database is SQL Server 2008 R2

+8
sql sql-server sql-server-2008-r2
source share
1 answer

There are many ways to achieve this. Why do you need this?

one.

 SELECT 'ABC' As title Select * from ABC SELECT 'CD' As title Select * from CD SELECT 'ABC' As title Select * from EN 

2.

 Select 'ABC' As title, * from ABC Select 'CD' As title, * from CD Select 'EN' As title, * from EN 

3.

Works for SQL Server . Not sure about other db's

 PRINT 'ABC' Select * from ABC PRINT 'CD' Select * from CD PRINT 'ABC' Select * from EN 
+13
source share

All Articles