我正在用糟糕的時間生成一個rdlc報表,以按客戶端給出的預定義格式顯示報表。如何使用sql在四個sql表中顯示rdlc中的銷售彙總
客戶給定的格式 Output format http://i29.tinypic.com/4t9g7b.jpg
正如你可以看到紅色的背景是我的問題區域,項目「A」的價格已經三次改變。並據此顯示其銷售額,損壞和退款數量。我有4個表產品,銷售日誌,破損,銷售退貨。產品表包含項目的最新(當前)價格,但SalesLog,Breakages和SalesReturn表格包含銷售,破損和銷售退貨時的價格。我已經爲SalesLog,Breakges和SalesReturn編寫了查詢,它根據ProductCode,Price和Quantity顯示行。但我不明白如何合併他們的(4個表格輸出)輸出以顯示下面的結果。
查詢爲SalesLog
SELECT [Products].pCode AS Code,
[Products].pName AS Item,
SalesLog.[Price] AS Price ,
COUNT(*)AS Quantity ,
SUM(SalesLog.[Price]) AS Total
FROM SalesLog
INNER JOIN [Products] ON [Products].pCode = SalesLog.ProductCode
WHERE BillDate = '07/01/2010'
GROUP BY [Products].pCode,[Products].pName ,
SalesLog.[Price]
查詢有關損毀
SELECT [Products].pCode AS Code,
[Products].pName AS Item,
Breakages.[Price] AS Price ,
COUNT(*)AS Quantity ,
SUM(Breakages.[Price]) AS Total
FROM Breakages
INNER JOIN [Products] ON [Products].pCode = Breakages.ProductCode
WHERE BillDate = '07/01/2010'
GROUP BY [Products].pCode,[Products].pName ,
Breakages.[Price]
查詢爲SalesReturn
SELECT [Products].pCode AS Code,
[Products].pName AS Item,
Breakages.[Price] AS Price ,
COUNT(*)AS Quantity ,
SUM(Breakages.[Price]) AS Total
FROM Breakages
INNER JOIN [Products] ON [Products].pCode = Breakages.ProductCode
WHERE BillDate = '07/01/2010'
GROUP BY [Products].pCode,[Products].pName ,
Breakages.[Price]
產品表
CREATE TABLE [dbo].[Products](
[ProductId] [int] IDENTITY(1,1) NOT NULL,
[pName] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[pSize] [int] NULL,
[pPrice] [decimal](10, 2) NULL,
[pPackQty] [int] NULL,
[pGroup] [int] NULL,
[pCode] [int] NULL,
[OpenStock] [int] NULL,
[CloseStock] [int] NULL,
[YrlyOpenStock] [int] NULL,
CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED
(
[ProductId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
誰能幫助我,或提出任何把戲做到這一點。
在此先感謝.....
感謝您幫助 – 2010-07-20 01:47:22