存储和查询日期,您将避免一大堆问题
我第一次尝试在sql server中编写存储过程,代码如下。在这里,当我在查询的末尾添加"with rollup"时,它显示错误"语法不正确靠近带有""的关键字
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'
With rollup
需要位于order by
之前。它与group by
有关
select Date, SUM(QT1), SUM(QTY2), SUM(qTY3) FROM dbo.TABLE1
where date between @startdate and @enddate
group by Date WITH ROLLUP
order by Date
此外,如果使用日期数据类型