Skip to content
Advertisement

SQL new table with conditions

I have a table and I want through sql to parse it into another table. The problem is that there is a condition: There are 3 columns in old version

And I want to store them into new table’s column like :

Thanks in advance.

Advertisement

Answer

You can use case expressions and string concatenation, like so:

This uses standard string concatenation operator ||; some databases have another operator or function.

Some databases also support concat_ws(), which simplifies the expression a little:

You can easily create a new table starting from this query, using the insert ... select syntax, although I would not recommend storing this derived information: instead, you can create a view, or add computed column in the original table.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement