I'm trying to concatenate a string:
concat(product," (",cast(created_date as string)," - ",cast(end_date as string),") ")
in Output I get :
Row String
1 Product_B (12-02-2020 - 21-04-2020)
2 Product_A (10-01-2020 - 11-02-2020)
3 Product_C (14-05-2020 - 19-07-2020)
So I want to add a line break in concatenate string And as a result, receive:
Row String
1 Product_B
(12-02-2020 - 21-04-2020)
2 Product_A
(10-02-2020 - 11-02-2020)
3 Product_C
(14-05-2020 - 19-07-2020)
What needs to be added to get break a string line?
Consider below option
select *,
format('%s\n(%s - %s)', product, created_date, end_date) rip
from `project.dataset.table`
if applied to sample data in your question -
with `project.dataset.table` as (
select 'Product_B' product, '2020-02-12' created_date, '2020-04-21' end_date union all
select 'Product_A', '2020-01-10', '2020-02-11' union all
select 'Product_C', '2020-05-14', '2020-07-19'
)
output is
In case if your dates column are of DATE data type - use below instead
select *,
format('%s\n(%t - %t)', product, created_date, end_date) rip
from `project.dataset.table`
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments