我在我的报告服务中使用的sql server上有这个查询,现在我需要将它转换为本地报告(rdlc)并使用ms访问作为后端。
WITH SuperSelect AS
( SELECT d.CaseNumber AS 'CASE NO.',
'ODU' AS MATERIAL, d.ItemNumber AS 'BOM NO.',
h.ModelNumber AS 'P/N',
h.Description AS 'DESCRIPTION',
d.Quantity AS 'QTY',
'PCS' AS UOM,
CAST(d.Quantity AS int) * 5.9 AS 'GW(KG)',
CAST(d.Quantity AS int) * 5 AS 'NW(KG)',
'0.35*0.35*0.22' AS 'MEASUREMENT(CBM)',
d.Batch AS 'PL',
d.ContractNumber AS 'Contract Number',
d.Consignee AS 'Consignee',
d.Destination AS 'Destination',
d.SO_Number AS 'Invoice',
d.PO_Number AS 'PO Number',
d.Shiplist_Qty AS 'Total Quantity'
,(
SELECT COUNT (CaseNumber)as CaseNumber
FROM
(
SELECT DISTINCT (CaseNumber) FROM TableA d
INNER JOIN TableB h
ON d.ItemNumber = h.ItemNumber
WHERE (d.Batch =@BatchCode)) as countCase) AS CountCase
FROM DropshipPackinglist
INNER JOIN h
ON d.ItemNumber = h.ItemNumber
WHERE (d.Batch =@BatchCode)
)
Select *,Sum([QTY]) OVER (partition BY ss.[CASE NO.])AS'TOTALVOLUME',CASE
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 31 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 36 THEN '1090x730x1460'
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 25 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 30 THEN '1090x730x1230'
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 19 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 24 THEN '1090x730x1000'
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 13 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 18 THEN '1090x730x780'
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 7 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 12 THEN '1090x730x570'
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 3 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 6 THEN '1090x730x350'
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 1 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 2 THEN '570x400x420'
WHEN sum([QTY]) OVER (partition BY ss.[CASE NO.]) >= 0 AND sum([QTY]) OVER (partition BY ss.[CASE NO.]) <= 1 THEN '350x350x220'
ELSE 'Unkown' END AS 'TOTAL VOLUME (MM3)'
FROM SuperSelect ss
表示感谢
答案 0 :(得分:5)
Access中不存在公用表表达式(WITH
块)和CAST
函数。您必须基本上将其重写为Access中的单独查询,以获得与SQL Server中相同的结果。当然,分区的概念超出了Access对任何内置函数的作用。您可能需要一系列嵌套的IIf
函数和许多其他工具来使这个坏男孩在Access中工作。仔细查看您的公司,找到有编写Access查询经验的人。
然而,听起来你的数据没有移动,只是查询,是吗?更好的建议是将其添加到SQL Server中的View中,然后将其添加为链接表(Access可以从外部表或视图创建虚拟表),然后您可以编写查询在Access中基于此结果。 (Example here)