简体   繁体   中英

access statement convert to Sql

我该如何转换为T-Sql?

IIf([ESSValue]<>0,Int([ESSValue]*100),"")

I think the following pretty much does what you want:

select coalesce(cast(EssValue * 100 as int), 0)

Here is the thinking. The comparison to zero is unimportant, because 0 times any value is going to be zero. The iif() returns an integer (I think) because the "then" argument is an integer; the empty string gets converted to zero.

I'm not 100% certain about the last statements with regard to MS Access, but that is how iif() works in SQL Server.

I should add. Although I don't approve of iif() for conditional expressions (because case is the standard and more powerful), SQL Server does support it. So you could write:

IIf([ESSValue]<>0, cast([ESSValue]*100 as int), '')

Note: As I mentioned earlier, the '' will be converted to 0 .

CASE WHEN ESSValue <> 0 
     THEN CAST(ESSValue * 100 AS INT)
     ELSE NULL
END as fieldname

For case expression the default is NULL if doesn't meet any condition, so you dont really need the ELSE condition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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