Home Forums SQL Server 7,2000 T-SQL Update Row with Combination of Values RE: Update Row with Combination of Values

  • Is this the kind of thing you are after?

    create table #temp (name varchar(50), Code varchar(50), CodeDesc varchar(50), Jan int,Feb int)

    set nocount on

    insert into #temp values ('JohnGinglehim', '45','Sick', 16, 0)

    insert into #temp values ('JohnGinglehim', '50','Vac', 0, 8)

    insert into #temp values ('HerrSchmidt', '45','Sick', 0, 8)

    insert into #temp values ('MasterJohns', '50','Vac', 8, 0)

    insert into #temp

    select name,

    '50' as Code,

    'SickVac' as codedsc,

    sum(Jan) as Jan,

    sum(Feb) as Feb

    from #temp

    where CodeDesc = 'Vac' or CodeDesc = 'Sick'

    group by name

    delete from #temp where CodeDesc = 'Sick' or CodeDesc = 'Vac'

    -- or

    -- update #temp set jan = 0, Feb = 0 where CodeDesc = 'Sick' or CodeDesc = 'Vac'

    select * from #temp

    drop table #temp