Case conditional when updating data? | Community
Skip to main content
Level 6
October 16, 2023
Solved

Case conditional when updating data?

  • October 16, 2023
  • 1 reply
  • 1315 views

In order to match a Recipients column, I need to satisfay this conditions:

1.- If customer_cic is length 8, then add 4 spaces at the begging. 
2.- If customer cic is length 12, leave it as it is.


I tried: Case(When(Length(customer_cic)==12,customer_cic, Else('    '+customer_cic)) 

But is giving me error.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by _Manoj_Kumar_

Hello @god_prophet 

 

The correct syntax is:

 

Case(When(Length(customer_cic)=12,customer_cic), Else(' '+customer_cic))

 

1 reply

_Manoj_Kumar_
Community Advisor
_Manoj_Kumar_Community AdvisorAccepted solution
Community Advisor
October 17, 2023

Hello @god_prophet 

 

The correct syntax is:

 

Case(When(Length(customer_cic)=12,customer_cic), Else(' '+customer_cic))

 

     Manoj     Find me on LinkedIn
Level 6
October 17, 2023

hi @_manoj_kumar_ , I'm getting this error with  that code:

10/17/2023 9:38:07 AM PGS-220000 PostgreSQL error: ERROR: operator does not exist: integer == integer LINE 1: ...cional = case when char_length(W0.sCustomer_cic) == 12 then... ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. .

Then I tried: 

Case(When(Length(toString(customer_cic))==12,customer_cic), Else(' '+customer_cic))

But gave me this error. 

10/17/2023 9:32:51 AM PGS-220000 PostgreSQL error: ERROR: operator does not exist: integer == integer LINE 1: ...cional = case when char_length(W0.sCustomer_cic) == 12 then... ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. .

I request your kindly help.


 



Level 6
October 17, 2023

Ok, this worked: 

Case(When(Length(customer_cic)=12,customer_cic), Else(' '+customer_cic))


Thank you, Manoj.