我第一次尝试在 sql server 中编写存储过程,代码如下。在这里,当我在查询末尾添加“with rollup”时,它显示错误“关键字 with 附近的语法不正确”
DROP PROCEDURE FIRSTPROCEDURE
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE FIRSTPROCEDURE
@startdate nchar(8), @enddate nchar(8)
AS
BEGIN
SET NOCOUNT ON;
select Date, SUM(QT1), SUM(QTY2), SUM(qTY3) FROM dbo.TABLE1
where date between @startdate and @enddate
group by Date
order by Date
WITH ROLLUP
END
GO
并尝试执行如下程序:
exec firstprocedure '20120501', '20120525'