Posted By

lottegis on 08/18/14


Tagged


Versions (?)

Conditional SQL statement


 / Published in: SQL
 

Example below

  1. SELECT CASE COLUMN WHEN 'search_string' THEN 'replace_string1' ELSE 'replace_string2' END AS column_rename
  2. FROM TABLE
  3.  
  4.  
  5. --Example
  6. SELECT OBJECTID,
  7. CASE PDF_NAME WHEN '' THEN '' ELSE '<a href="./doc/logbooks/'>' + PDF_NAME + '</a>' END AS LogBooks,
  8. CASE DAILY_REP WHEN '' THEN '' ELSE '<a href="./doc/Reports/'>' + DAILY_REP + '</a>' END AS DailyReport,
  9. STR_NAME, Shape
  10. FROM DatabaseName.TableName

Report this snippet  

You need to login to post a comment.