简体   繁体   English

访问IIF到SQL语句的转换

[英]Access IIF to SQL Statement convert

I have access query and I am converting it to TSQL(SQL Server). 我有访问查询,并将其转换为TSQL(SQL Server)。 I'm looking for the equivalent to the Access IIF statement in SQL Server. 我正在寻找与SQL Server中的Access IIF语句等效的方法。

Below is the statement I am trying to convert; 以下是我要转换的语句;

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)))

I tried to use Case but I am not able to write it. 我尝试使用Case,但无法编写它。 Could you please convert the above query in CASE statement. 您能否在CASE语句中转换以上查询。

This is quite ugly but give this a try: 这非常丑陋,但可以尝试一下:

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

how to change this Query in sql server 如何在SQL Server中更改此查询

    ("select IIF(MAX(bill_bno) IS NULL,1,MAX(bill_bno)+1) from rec_all 
where rw=0 and iif(month(bill_date)>=1 AND month(bill_date)=3,
year(bill_date)-1, year(bill_date))=" & IIf(Month(Date) >= 1 AND Month(Date) <= 3, Year(Date) - 1, Year(Date))) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM