sql - inserting data with different value then source in temp table -
i need pull data temp table can group product type have different variants of product , need insert variants original variant. wrote code follows still isn't working
if exists (select * sys.tables name '#temp%') drop table #temp create table #temp ( product varchar(max) null, failure_code varchar(max) null ) if product in ( 18, 19, 20, 23, 24, 25 ) select product = 'dsd 4136' insert #temp (product, failure_code) select product.prod_desc product, test_failure_code.failure_code repair inner join test_failure_code on repair.id_test_failure_code = test_failure_code.id_test_failure_code inner join production_event_details on repair.id_production_event_details = production_event_details.id_production_event_details inner join product on production_event_details.prod_id = product.prod_id inner join repair_scm_bom_item on repair.id_repair = repair_scm_bom_item.id_repair inner join repair_fault on repair_scm_bom_item.id_repair_fault = repair_fault.id_repair_fault inner join scm_bom_item on repair_scm_bom_item.id_scm_bom_item = scm_bom_item.id_scm_bom_item group product.prod_desc, test_failure_code.failure_code select * #temp drop table #temp
the statement
if product in ( 18, 19, 20, 23, 24, 25 ) select product = 'dsd 4136'
wont anything, need use in insert statement using case statement, select product dsd 4136 when product 1 of listed options:
insert #temp (product, failure_code) select case when product.prod_desc in ( 18, 19, 20, 23, 24, 25 ) 'dsd 4136' else product.prod_desc end product, test_failure_code.failure_code repair inner join test_failure_code on repair.id_test_failure_code = test_failure_code.id_test_failure_code inner join production_event_details on repair.id_production_event_details = production_event_details.id_production_event_details inner join product on production_event_details.prod_id = product.prod_id inner join repair_scm_bom_item on repair.id_repair = repair_scm_bom_item.id_repair inner join repair_fault on repair_scm_bom_item.id_repair_fault = repair_fault.id_repair_fault inner join scm_bom_item on repair_scm_bom_item.id_scm_bom_item = scm_bom_item.id_scm_bom_item group product.prod_desc, test_failure_code.failure_code
Comments
Post a Comment