An update with a Group by

  • -- I've posted the DDL of the 2 tables i like to apply an update on the column Declined_Ind

    -- setting it to 1 or 0 depending on the dch_code, from both tables i need to join both tables together

    -- and group by the source_system and log_number so i don't show any duplicates

    -- The expected out put should be this, based on the data in both tables

    --Source system log number dch_code Declined_ind

    -- sys_1  100370613   26            1

    -- sys_1  100370614    1     0

    -- sys_1  100370615    2     0

    -- If i have the dch_code set to 26 the Declined_ind should equal to  1

    -- also grouping all together in this case the log number 100370613

    -- is in the table 2 times but in the result set, its only showen once.

     

    drop table #tbl_Hot_Transferred_Staging

    drop table #tbl_raw_icss_call_actions

    create table #tbl_Hot_Transferred_Staging

    (

     source_system varchar(10),

     log_number nvarchar(10),

     Declined_Ind int

    )

    insert into #tbl_Hot_Transferred_Staging(source_system,log_number,Declined_Ind)

    values ('sys_1','100370613',NULL)

    insert into #tbl_Hot_Transferred_Staging(source_system,log_number,Declined_Ind)

    values ('sys_1','100370614',NULL)

     

    create table #tbl_raw_icss_call_actions

    (

     source_system varchar(10),

     log_number nvarchar(10),

     dch_code int

    )

    insert into #tbl_raw_icss_call_actions(source_system,log_number,dch_code)

    values ('sys_1','100370613','26')

    insert into #tbl_raw_icss_call_actions(source_system,log_number,dch_code)

    values ('sys_1','100370614','01')

    insert into #tbl_raw_icss_call_actions(source_system,log_number,dch_code)

    values ('sys_1','100370615','02')

    insert into #tbl_raw_icss_call_actions(source_system,log_number,dch_code)

    values ('sys_1','100370613','26')

  • If I understand your post correctly, you don't need to group by in the UPDATE. just use the distinct keyword in the select statement following the update.

    SQL guy and Houston Magician

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply