如何给存储过程的下一行 [英] how to give next line to stored procedure

查看:62
本文介绍了如何给存储过程的下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储程序输出如下



SNO课程Startdate Enddate描述



1 ERS ​​27 2015年5月2015年5月30日座位20

1 MFA 2015年6月5日2015年6月5日座位30

1 PSC 2015年6月4日2015年6月6日座位40

2 ERS 29 2015年5月30日2015年席位20

2 MFA 2015年6月4日2015年6月2015席位30

2 PSC 2015年6月6日2015年6月9日席位40



我想要输出如下给下一行如下



1 ERS ​​27 2015年5月30日2015年20个席位/>
1 MFA 2015年6月5日2015年6月5日席位30

1 PSC 2015年6月4日2015年6月6日席位40



2 ERS ​​29 2015年5月30日2015年席位20

2 MFA 2015年6月4日2015年6月8日座位30

2 PSC 2015年6月6日2015年6月9日座位40





我怎么能在sql server中执行存储过程

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

推荐答案

如果我正确理解了这个问题你想要一个每组SNO之间的空行



如果是这种情况,SQL不是为格式化输出而设计的。应始终使用专为此设计的工具进行格式化。 SQL用于获取和操作数据。



基本上你可以使用UNIONs或使用游标获取数据,然后将结果添加到临时表中并选择从那个或类似的东西,但我不建议这样做。



看看在呼叫方面可用的工具。如果您将数据提取到gridview中,也许您可​​以使用分组,或者如果您需要报告,也许Sql Server报告工具将是解决方案等等...
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...


您不需要:分离带空行的数据是演示功能,而不是数据访问功能。您可以在演示文稿软件中而不是在SQL中执行此操作。
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.


您可以添加新的行变量,如下所示。它用于根据需要插入存储过程输出的下一行。



You can add new line variable as below. It is used to insert next line for the stored procedure output, as needed.

DECLARE @LINEBREAK AS varchar(2)
SET @LINEBREAK = CHAR(13) + CHAR(10)


这篇关于如何给存储过程的下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆