postgresql - Using Convert on an ELSE CASE SQL query -


i performing sql query in postgres, selects numeric field. need display string value result of select, using case statement this:

select  case numeric_field when 100 'some string' when 200 'some other string' 

the problem if numeric field has other value (like 300 example), need display value (as string of course). try put convert on else this

... else convert(varchar(10),numeric_field) 

but didn't work. how do this?

select case numeric_field           when 100 'some string'           when 200 'some other string'           else numeric_field::text        end result 
  • your statement incomplete, end missing. read manual here.
  • to output numeric field text, cast text: numeric_field::text, postgres specific short form of sql standard call:

    cast (numeric_field text) 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -