Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Store procedure output as follows

SNO Course Startdate Enddate Description

1 ERS 27 may 2015 30 may 2015 seats 20
1 MFA 2 june 2015 5 june 2015 seats 30
1 PSC 4 June 2015 6 June 2015 seats 40
2 ERS 29 may 2015 30 may 2015 seats 20
2 MFA 4 june 2015 8 june 2015 seats 30
2 PSC 6 June 2015 9 June 2015 seats 40

I want output as follows to give next line as follows

1 ERS 27 may 2015 30 may 2015 seats 20
1 MFA 2 june 2015 5 june 2015 seats 30
1 PSC 4 June 2015 6 June 2015 seats 40

2 ERS 29 may 2015 30 may 2015 seats 20
2 MFA 4 june 2015 8 june 2015 seats 30
2 PSC 6 June 2015 9 June 2015 seats 40


for that how can i do in sql server in stored procedure
Posted

If I understood the question correctly you'd like a blank line between each group of SNO's

If that is the case, SQL is not designed for formatting the output. Formatting should always be done using tools designed for that. SQL is designed for fetching and manipulating data.

Basically you could do this using UNIONs or fetching the data using a cursor and then adding the results into a temporary table and selecting from that or something similar, but I wouldn't suggest doing that.

Have a look at the tools that are available for you on the calling side. If you fetch the data into a gridview perhaps you can use grouping or if you need reporting perhaps Sql Server Reporting Tools would be the solution and so on...
 
Share this answer
 
You don't: separating data with blank lines is a presentation feature, not a data access feature. You do this in your presentation software, not in SQL.
 
Share this answer
 
You can add new line variable as below. It is used to insert next line for the stored procedure output, as needed.

SQL
DECLARE @LINEBREAK AS varchar(2)
SET @LINEBREAK = CHAR(13) + CHAR(10)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900