How To Insert Title At Start of SQL Results and Between Another SQL Result Sets

I have three queries in one file.

I would like to insert a title line at the beginning of the first set of results, and between the next two queries, to show the change of information.

Don't want want my users to need use three separate queries, one and done preferred.

Using MS SQL Server Management Studio 18.4

PRINT 'Title for Query One'

SELECT * FROM myTable1 -- query 1

PRINT 'Title for Query Two'

SELECT * FROM myTable2 -- query 2

PRINT 'Title for Query Three'

SELECT * FROM myTable3 -- query 3
1 Like

Hot DANG!!

Thank you.

Well, I thought that was going to work, but...that did not show in the results...

The PRINT output will show in the Messages tab, not grid results. If they were outputting to Text Results, then they would see it.

Change PRINT to SELECT in order to see the headings in Grid Results.

Maybe this is an option:

SELECT '--' AS Unit, '---------' AS System
UNION
SELECT Unit, System
FROM FirstQuery
UNION 
SELECT '--' AS Unit, '---------' AS System
UNION
SELECT Unit, System
FROM SecondQuery

If it is, make sure you underestand the difference between UNION and UNION ALL.