金箭联盟

Golden Arrows with Union

我在 SAP B1 (SQL) 中有一个查询,我在其中使用 UNION ALL 合并来自三个表的数据。我已将其设置为 Boyum 的 B1 可用性包中的通用函数,但由于三个来源,我不知道如何通过 T0.[DocNum] 列上的格式向导使金色箭头起作用。有人可以帮忙吗?

SELECT T0.[DocDate], T0.[DocNum], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum]
FROM ODPI T0
WHERE T0.DocDate>='[%0]' and T0.DocDate<='[%1]'

UNION ALL

SELECT T0.[DocDate], T0.[DocNum], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum]
FROM OINV T0
WHERE T0.DocDate>='[%0]' and T0.DocDate<='[%1]'

UNION ALL

SELECT T0.[DocDate], T0.[DocNum], T0.[CardCode], T0.[CardName], -1 * T0 [DocTotal], -1 * T0.[VatSum]
FROM ORIN T0
WHERE T0.DocDate>='[%0]' and T0.DocDate<='[%1]'

基于您使用的是 Boyum 的 B1 可用性包这一事实,您可以利用他们的 SQL 报告通用功能来获取与列关联的正确对象类型。

您需要将不同源表的 DocNums 拆分到不同的列中,以便您可以将类型应用到正确的列。

您为此使用的查询是这样的:

SELECT T0.[DocDate], T0.DocNum AS ODPI_DocNum, null as OINV_DocNum, null as ORIN_DocNum, T0.[DocNum], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum]
FROM ODPI T0
WHERE T0.DocDate>='[%0]' and T0.DocDate<='[%1]'

UNION ALL

SELECT T0.[DocDate], null AS ODPI_DocNum, T0.DocNum as OINV_DocNum, null as ORIN_DocNum, T0.[DocNum], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum]
FROM OINV T0
WHERE T0.DocDate>='[%0]' and T0.DocDate<='[%1]'

UNION ALL

SELECT T0.[DocDate], null AS ODPI_DocNum, null as OINV_DocNum, T0.DocNum as ORIN_DocNum, T0.[DocNum], T0.[CardCode], T0.[CardName], -1 * T0.[DocTotal], -1 * T0.[VatSum]
FROM ORIN T0
WHERE T0.DocDate>='[%0]' and T0.DocDate<='[%1]'

下图显示了您需要如何设置通用函数,特别是格式字段: