Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give a title to each sql query output

I have a sql script which is nothing but a combination of multiple "Select" queries like:

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

Now when I execute it, I use to get output like

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

Requirement: I need some title to be displayed for each of the output.

To be more clear,I want output like:

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

like image 308
Pradeep Avatar asked Aug 30 '12 07:08

Pradeep


People also ask

How do I add headings in SQL query?

SQL Server just gives you the raw data, how you present it depends on the language/application you are using. You need to use a reporting tool, e.g. SQL Server Reporting Services, or Crystal Reports or something like this. There is nothing called header, all in COLUMNS and ROWS.

What is %% in SQL query?

The SQL LIKE Operator There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters.


1 Answers

There're a lot of ways for achieving this. What exactly do you need this for?

1.

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
like image 185
hgulyan Avatar answered Oct 20 '22 13:10

hgulyan