SSRS 2008中的可选参数

时间:2014-07-24 13:32:08

标签: sql reporting-services

如果有人能帮助我,我将不胜感激。

我有一个查询,它将我想要的销售数据提取到SSRS报告中。这里显示:

SELECT SH.[CompanyKey]
  ,[DeliveryDate]
  ,[CustomerKey]
  ,AcAccounts.ShortDesc
  ,SH.[ItemKey]
  ,ITEM.ItemDesc
  ,[InvoiceDate]
  ,[SalesRep1Key]
  ,[SalesRep2Key]
  ,[ReturnCancelCode]
  ,[ShipToKey]
  ,[BillToKey]
  ,[RouteNo]
  ,[PaymentTypeKey]
  ,[DeliveryTypeKey]
  ,[OrderNo]
  ,[OrderDate]
  ,[OrderStatus]
  ,[PostingPeriod]
  ,[Quantity]
  ,[QuantityUnit]
  ,[QuantityConvFactor]
  ,[OldOrderNo]
  ,[OrderVersionNo]
  ,[PONumber]
FROM 
[Company].[dbo].[FactSalesHistoryDS] SH
INNER JOIN [FRESHWAY].[dbo].[DimFiAcAccounts] AcAccounts ON
AcAccounts.AccountKey = SH.CUSTOMERKEY
INNER JOIN [freshway].[dbo].[dimitem] ITEM ON
SH.ItemKey = ITEM.ItemKey
WHERE INVOICEDATE BETWEEN @StartDate AND @EndDate
AND SH.ItemKey = @ItemKey

我现在按项目编号组织工作正常但我也希望此报告可以选择使用客户密钥参数,以便我可以按客户或每个项目运行报告。这可以在同一报告中执行,还是只需要创建报表:按项目销售和按客户销售

1 个答案:

答案 0 :(得分:1)

我建议你在哪里使用案例陈述。假设您有一个名为@CustomerKey的参数,它可以与@ItemKey一起使用,它也可以为空。然后您的选择将如下所示:

SELECT SH.[CompanyKey]
  ,[DeliveryDate]
  ,[CustomerKey]
  ,AcAccounts.ShortDesc
  ,SH.[ItemKey]
  ,ITEM.ItemDesc
  ,[InvoiceDate]
  ,[SalesRep1Key]
  ,[SalesRep2Key]
  ,[ReturnCancelCode]
  ,[ShipToKey]
  ,[BillToKey]
  ,[RouteNo]
  ,[PaymentTypeKey]
  ,[DeliveryTypeKey]
  ,[OrderNo]
  ,[OrderDate]
  ,[OrderStatus]
  ,[PostingPeriod]
  ,[Quantity]
  ,[QuantityUnit]
  ,[QuantityConvFactor]
  ,[OldOrderNo]
  ,[OrderVersionNo]
  ,[PONumber]
FROM 
[Company].[dbo].[FactSalesHistoryDS] SH
INNER JOIN [FRESHWAY].[dbo].[DimFiAcAccounts] AcAccounts ON
AcAccounts.AccountKey = SH.CustomerKey 
INNER JOIN [freshway].[dbo].[dimitem] ITEM ON
SH.ItemKey = ITEM.ItemKey
WHERE INVOICEDATE BETWEEN @StartDate AND @EndDate
AND SH.ItemKey = CASE WHEN @ItemKey IS NOT NULL THEN @ItemKey ELSE SH.ItemKey END
AND SH.CustomerKey = CASE WHEN @CustomerKey IS NOT NULL THEN @CustomerKey  ELSE SH.CustomerKey END