Add blank line between certain rows SQL query

To avoid formatting an Excel file after I use DTS to output a query, I'd like to add a blank line in the output.
Schl   Section          #Students
A        Alg            40
A        Alg            30
 BLANK LINE HERE
A     SocStu            60
A     SocStu         70
   BLANK LINE HERE

select schl,courseid,noofstudents
???
from table

Open in new window

lbarnett419Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brejkCommented:
Quite a lot of combinations in ORDER BY clause but it may lead you to some solution:
DECLARE @T TABLE (Schl char(1), Section varchar(6), [#Students] int)
INSERT INTO @T (Schl, Section, [#Students])
SELECT 'A', 'Alg', 40
UNION ALL
SELECT 'B', 'Alg', 30
UNION ALL
SELECT 'A', 'SocStu', 60
UNION ALL
SELECT 'B', 'SocStu', 70
 
SELECT 
  ISNULL(Schl,'') AS Schl, 
  CASE WHEN Schl IS NULL THEN '' ELSE Section END Section, 
  CASE WHEN [#Students] IS NULL THEN '' ELSE CAST([#Students] AS varchar(20)) END AS Students
FROM
(
SELECT * 
FROM @T
UNION ALL
SELECT DISTINCT NULL, Section, NULL
FROM @T
) AS Q
ORDER BY
  Q.Section, 
  CASE 
    WHEN Q.Schl IS NULL THEN 'z'
    ELSE 'a' + Q.Schl
  END,
  CASE 
    WHEN Q.[#Students] IS NOT NULL THEN Q.[#Students] 
    ELSE 99999999
  END

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lbarnett419Author Commented:
Got the concept. Thanks!
0
Kevin CrossChief Technology OfficerCommented:
I got distracted, so this is way late; however, you could utilize the fact that NULLs will come in as blank data.
WITH classes(Schl, Section, NoOfStudents) AS (
	SELECT 'A', 'Alg', 40
	UNION ALL SELECT 'A', 'Alg', 30
	UNION ALL SELECT 'A', 'SocStu', 60
	UNION ALL SELECT 'A', 'SocStu', 70
)
SELECT CASE GROUPING(NoOfStudents) WHEN 1 THEN NULL ELSE Schl END AS [Schl]
, CASE GROUPING(NoOfStudents) WHEN 1 THEN NULL ELSE Section END AS [Section]
, CASE GROUPING(NoOfStudents) WHEN 1 THEN NULL ELSE NoOfStudents END AS [#Students]
FROM classes
GROUP BY Schl, Section, NoOfStudents WITH ROLLUP

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.