Skip to content
Advertisement

use concat or replace for values in the middle SQL / Postgresql

how to use concat for values in the middle,

I have the following data

id,work_id,deptcd,"desc"
id,workcd,"desc"

and I want to change it to be like this

id,work_id,deptcd as code,"desc"
id,workcd as code,"desc"

I tried with a query like this, but the results did not match what I expected

SELECT 
CASE WHEN columnmaster ILIKE '%cd%' THEN concat(columnmaster,' as code') ELSE columnmaster END AS code
,* FROM data

this is the result of my query

id,work_id,deptcd,"desc" as code
id,workcd,"desc" as code

Advertisement

Answer

You can simply use

repcace(columnmaster, 'cd', 'cd as code')
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement