Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sql Bigquery – concat two columns into a new column

I want to concat two columns shown below into one new column.

A_Bill_ID   B_BILL_ID

I’m using this query:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT
CONCAT( A_Bill_ID , ' ', B_BILL_ID ) AS BILL_ID
FROM
`table.tmp_140222`

From this query, the result will be like this.

enter image description here

My problem is I want to concat only columns that don’t have a similar value so that the new column value will not duplicate two times. From the above result, the ID is duplicated since both of the columns has the same value.

Can anyone help me?

Thanks

>Solution :

You can use a case statement like this –

SELECT
case when A_Bill_ID = B_BILL_ID then a_bill_Id 
else CONCAT( A_Bill_ID , ' ', B_BILL_ID ) 
end AS BILL_ID
FROM `table.tmp_140222`
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading