Home > Enterprise >  Swapping columns and deleting column SQL BigQuery
Swapping columns and deleting column SQL BigQuery

Time:07-15

This is the Unclosed identifier literal at my "from" how do i add both the query you sent and this query together with the select. Also I forgot to mention I want the update query before the select query i want it to update first then do whatever its in the select

SELECT *,
                      TIMESTAMP_DIFF(start_date, expected_start_date, MINUTE) AS Difference_Start_Time,
                      TIMESTAMP_DIFF(end_date, expected_end_date, MINUTE)     AS Difference_End_Time,

                      CASE
                          WHEN TIMESTAMP_DIFF(start_date, expected_start_date, MINUTE) <= 0 THEN TRUE
                          WHEN TIMESTAMP_DIFF(start_date, expected_start_date, MINUTE) > 0 THEN FALSE
                          END AS Started_On_Time,
                      CASE
                          WHEN TIMESTAMP_DIFF(end_date, expected_end_date, MINUTE) <= 0 THEN TRUE
                          WHEN TIMESTAMP_DIFF(end_date, expected_end_date, MINUTE) > 0 THEN FALSE
                          END AS end_date_tracker,
                   CASE
                          WHEN end_date is null then 'FAILED'
                          ELSE 'COMPLETED'
                          END AS status_tracker
               FROM `np-inventory-planning-thd.IPP_SLA.sla_table,

update `np-inventory-planning-thd.IPP_SLA.test_sla_table`
set expected_start_date = timestamp(CONCAT( EXTRACT(DATE FROM TIMESTAMP(start_date)),' '
,EXTRACT(TIME FROM TIMESTAMP(expected_start_date)) )), expected_end_date = timestamp(CONCAT( EXTRACT(DATE FROM TIMESTAMP(end_date)),' '
,EXTRACT(TIME FROM TIMESTAMP(expected_end_date)) ))
where 1=1

CodePudding user response:

try below.


update table_name
set expected_start_date = timestamp(result)
where 1=1;


ALTER TABLE table_name DROP COLUMN IF EXISTS result;

CodePudding user response:

See the code based on new feed.


update np-inventory-planning-thd.IPP_SLA.test_sla_table 
set expected_start_date = timestamp(CONCAT( EXTRACT(DATE FROM TIMESTAMP(start_date)),' ',EXTRACT(TIME FROM TIMESTAMP(expected_start_date)) )) 
where 1=1;

CodePudding user response:

Try this.


update `np-inventory-planning-thd.IPP_SLA.test_sla_table`
set expected_start_date = timestamp(CONCAT( EXTRACT(DATE FROM TIMESTAMP(start_date)),' '
,EXTRACT(TIME FROM TIMESTAMP(expected_start_date)) )), 
expected_end_date = timestamp(CONCAT( EXTRACT(DATE FROM TIMESTAMP(end_date)),' '
,EXTRACT(TIME FROM TIMESTAMP(expected_end_date)) ))
where 1=1;

SELECT *,  TIMESTAMP_DIFF(start_date, expected_start_date, MINUTE) AS Difference_Start_Time, 

TIMESTAMP_DIFF(end_date, expected_end_date, MINUTE)  AS Difference_End_Time,

CASE WHEN TIMESTAMP_DIFF(start_date, expected_start_date, MINUTE) <= 0 THEN TRUE WHEN TIMESTAMP_DIFF(start_date, expected_start_date, MINUTE) > 0 THEN FALSE END AS Started_On_Time,

CASE WHEN TIMESTAMP_DIFF(end_date, expected_end_date, MINUTE) <= 0 THEN TRUE WHEN TIMESTAMP_DIFF(end_date, expected_end_date, MINUTE) > 0 THEN FALSE END AS end_date_tracker,

CASE WHEN end_date is null then 'FAILED' ELSE 'COMPLETED' END AS status_tracker 
FROM `np-inventory-planning-thd.IPP_SLA.sla_table`;
  • Related