我有访问查询,我将其转换为TSQL(SQL Server)。我正在寻找与SQL Server中的Access IIF语句等效的内容。
以下是我要转换的声明;
IIF(((ISNULL([Total], 0) * [SellThrough])/100)/IIF(ISNULL([NoOfStores], 0) = 0, 1, ISNULL([NoOfStores], 0))/IIF(ISNULL([FPWeeksOfSelling], 0) =
0, 1, ISNULL([FPWeeksOfSelling], 0)) < 0.1, 0, ((ISNULL([Total], 0) * [SellThrough])/100)/IIF(ISNULL([NoOfStores], 0) =
0, 1, ISNULL([NoOfStores], 0))/IIF(ISNULL([FPWeeksOfSelling], 0) = 0, 1, ISNULL([FPWeeksOfSelling], 0)))
我尝试使用Case但我无法编写它。你能否在CASE声明中转换上述查询。
答案 0 :(得分:2)
这很难看,但试试看:
CASE WHEN ((ISNULL([Total], 0) * [SellThrough]) / 100) /
CASE WHEN ISNULL([NoOfStores], 0) = 0 THEN 1 ELSE ISNULL([NoOfStores], 0) END
/ CASE WHEN ISNULL([FPWeeksOfSelling], 0) = 0 THEN 1 ELSE ISNULL([FPWeeksOfSelling], 0) END < 0.1 THEN 0 ELSE
((ISNULL([Total], 0) * [SellThrough]) / 100) / CASE WHEN ISNULL([NoOfStores], 0) = 0 THEN 1 ELSE ISNULL([NoOfStores], 0) END / CASE WHEN ISNULL([FPWeeksOfSelling], 0) = 0 THEN 1 ELSE ISNULL([FPWeeksOfSelling], 0) END END