好的,所以我需要将最初在 access 数据库上使用的查询转换为将在 SQL-Compact Edition 数据库上运行的查询。
在那个查询中,我有一个 IIF 语句(在 sql 中不起作用)
我查找的所有内容都表明我应该用 Case When 替换它。
这是我的原始代码:
Select [OrderNumber], [CustomerName], [PO_TAG], [Shape], [Size], [DrawingNumber],
[OrderBuildTime], [RequiredDateTime], [LatestStatusTime], [ExpectedCompletionDateTime],
[DateImported], Sum(IIF([Status] = 'Printed', PanelBuildTime, 0)) AS OrderBuildTimee from
SteelOrders
INNER JOIN FinalizedPrintedStickers
ON
SteelOrders.OrderNumber = LEFT(FinalizedPrintedStickers.SN,10)
GROUP BY SteelOrders.OrderNumber, [CustomerName], [PO_TAG], [Shape], [Size], [DrawingNumber],
[OrderBuildTime], [RequiredDateTime], [LatestStatusTime], [ExpectedCompletionDateTime],
[DateImported]
这是 IIF 声明:
Sum(IIF([Status] = 'Printed', PanelBuildTime, 0)) AS OrderBuildTimee
这就是我将 IIF 语句替换为:
Sum(CASE Status WHEN 'Printed' THEN PanelBuildTime ELSE 0) AS OrderBuildTimee
这是整个代码的后记:
Select [OrderNumber],
[CustomerName],
[PO_TAG],
[Shape],
[Size],
[DrawingNumber],
[OrderBuildTime],
[RequiredDateTime],
[LatestStatusTime],
[ExpectedCompletionDateTime],
[DateImported],
Sum(CASE Status WHEN 'Printed' THEN PanelBuildTime ELSE 0) AS OrderBuildTimee
From SteelOrders
INNER JOIN FinalizedPrintedStickers
ON
SteelOrders.OrderNumber = LEFT(FinalizedPrintedStickers.SN,10)
GROUP BY SteelOrders.OrderNumber, [CustomerName], [PO_TAG], [Shape], [Size], [DrawingNumber],
[OrderBuildTime], [RequiredDateTime], [LatestStatusTime], [ExpectedCompletionDateTime],
[DateImported]
这是我的新错误信息:
Major Error 0x80040E14, Minor Error 25501
> Select [OrderNumber],
[CustomerName],
[PO_TAG],
[Shape],
[Size],
[DrawingNumber],
[OrderBuildTime],
[RequiredDateTime],
[LatestStatusTime],
[ExpectedCompletionDateTime],
[DateImported],
Sum(CASE Status WHEN 'Printed' THEN PanelBuildTime ELSE 0) AS OrderBuildTimee
From SteelOrders
INNER JOIN FinalizedPrintedStickers
ON
SteelOrders.OrderNumber = LEFT(FinalizedPrintedStickers.SN,10)
GROUP BY SteelOrders.OrderNumber, [CustomerName], [PO_TAG], [Shape], [Size], [DrawingNumber],
[OrderBuildTime], [RequiredDateTime], [LatestStatusTime], [ExpectedCompletionDateTime],
[DateImported]
There was an error parsing the query. [ Token line number = 12,Token line offset = 58,Token in
error = ) ]