SQL Query - Get the number from 2 columns, into a 3rd one

38 Views Asked by At

I want to build the 3rd column within a query I have, it's a select query.

I tried some stuff like this:

enter image description here

Also thought of regex... It's for big data, so I'm concered about being efficient. Also though of a case switch... I'm using big query btw. Thoughts?? Thanks!

enter image description here

2

There are 2 best solutions below

3
Gordon Linoff On

If I understand correctly, the logic you want is:

select (case when regexp_like(col1, '^[0-9]+$' then col1 else col2 end)
0
AudioBubble On

well, I actually used case, because I had an additional field that would help me give an order to when to get the number. Case status when 'a' then col1, else col2

something like that. Ty!