简体   繁体   中英

Case statement in Bigquery

How to convert this IF statement in SQL using CASE statement

if address='US\Madison Drive' then 'ZIP1234'
elseif address='US\123 Madison Dr' then 'ZIP1234'
elseif address'US\123 Madison-Dr' then 'ZIP1234'
ELSE 'ZIP9999' END

I need to rewrite this statement using CASE statement in where condition

Select a.ID, NAME, Address, ZIP from 
table_A a left join table_B b
on a.ID = b.ID#
where {I need to put if condition mention above} 

How to convert this IF statement in SQL using CASE statement

case address 
  when 'US\Madison Drive' then 'ZIP1234'
  when 'US\123 Madison Dr' then 'ZIP1234'
  when 'US\123 Madison-Dr' then 'ZIP1234'
  else 'ZIP9999' 
end           

another option for this particular example

case when address in (
    'US\Madison Drive', 
    'US\123 Madison Dr', 
    'US\123 Madison-Dr') 
  then 'ZIP1234'
  else 'ZIP9999' 
end           
case address 
    when ('US' || CHR (92) || 'Madison Drive') then 'ZIP1234' 
    when ('US' || CHR (92) || '123 Madison Dr') then 'ZIP1234' 
    when ('US' || CHR (92) || '123 Madison-Dr') then 'ZIP1234' 
    else 'ZIP9999' end ``` 

**'\' was giving error**

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-2025 STACKOOM.COM