If anyone could help me out with this it would be greatly appreciated.
I have a query that is pulling our sales data that I want to put into an SSRS report.Shown here:
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
I presently have it organized by item number which is working fine but I would also like this report to have the option of having a parameter of customer key so that I can either run the report per customer or per item. Is this possible to do in the same report or do I need to just create to reports: Sales by Item and Sales by Customer
I would recommend using a case statement in your where. Say you have a parameter called @CustomerKey and it is nullable along with the @ItemKey which is also nullable. Your select would then be laid out like:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.