如何在商店过程中获取确切的参数

时间:2015-05-14 15:02:00

标签: c# sql-server winforms

我正在尝试从Sales表中记录两个基于月份的参数。它没有获得所选择的确切月份,而是激发了我所有的记录。我怎么能去做呢?

当我在一个WHERE子句中包含Monat列时,我得到一个空结果

我的sp:

CREATE PROC [dbo].[spMonthInfo]
(   
@Periode1 NVARCHAR (255),
@Periode2 NVARCHAR (255) 
)
AS
BEGIN
DECLARE @Dynamictbl nvarchar(MAX) =
N'SELECT
[t].[Monat], [t].[Project],[t].[Description],
[t].[Finance], --[t].[Project] AS [Entrance],

SUM(CASE WHEN [t].Monat = ' + @Periode1 + ' THEN [t].[Amount1] END) AS [Amount1Feb],
SUM(CASE WHEN [t].Monat = ' + @Periode2 + ' THEN [t].[Amount1] END) AS [Amount1March],
SUM(CASE WHEN [t].Monat = ' + @Periode1 + ' THEN [t].[Amount2] END) AS [Amount2Feb],
SUM(CASE WHEN [t].Monat = ' + @Periode2 + ' THEN [t].[ Amount2] END) AS [Amount2March],

FROM [dbo].[tblSales]


GROUP BY [t].[Monat],[t].[Project],[t].[Description],
[t].[Finance], --[t].[Project] AS [Entrance],

EXECUTE sp_executesql @Dynamictbl

END
GO
-- 
EXEC spMonthInfo @Periode1 = '02.2011', @Periode2 = '03.2011'

问题:image

0 个答案:

没有答案