简体   繁体   中英

Access db jet sql if else in query

i am using microsoft access jet sql.

i have table col1 and col2

i want to have if else check in select query like as follows

select col1, if(col2 <10) then 'less then 10' else if(col2 < =20) then 'less then 20')

any quick help

IIF([col2]<10, "Less then 10", IIF([col2]<=20, "Less then20", "something else"))

Use the SWITCH() function, which Access's (ACE's, Jet's, whatever's) analogy of Standard SQL's CASE expression eg

SELECT col1, 
       SWITCH ( 
               col2 < 10, 'Less than 10', 
               col2 <= 20, 'Less than or equal to 20', 
               TRUE, 'something else'
              ) AS col2_narrative, ...

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