"Sto provando per la prima volta a scrivere una procedura memorizzata in SQL Server e i codici come di seguito. Qui quando aggiungo" con rollup "alla fine della query, viene visualizzato l'errore" Sintassi errata vicino alla parola chiave con "
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
E ho provato a eseguire la procedura come di seguito:
exec firstprocedure "20120501", "20120525"
risposte:
2 per risposta № 1With rollup
deve venire prima del order by
. È legato al 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
Inoltre, eviterai tutta una serie di problemi se memorizzi e richiedi le tue date utilizzando il tipo di dati della data