Forum Replies Created

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

  • RE: going crazy with update statement! Plz help

    DB Dan (4/13/2011)


    Another way with just one update.

    UPDATE trans

    SET price = CASEWHEN relatedID IS NOT NULL

    THEN

    (select avg(price) from trans where id<=t.relatedid)

    ELSE

    (select avg(price) from trans where id<=t.id)...

  • RE: going crazy with update statement! Plz help

    DB Dan (4/13/2011)


    Another way with just one update.

    UPDATE trans

    SET price = CASEWHEN relatedID IS NOT NULL

    THEN

    (select avg(price) from trans where id<=t.relatedid)

    ELSE

    (select avg(price) from trans where id<=t.id)...

  • RE: going crazy with update statement! Plz help

    John Mitchell-245523 (4/13/2011)


    You need to do your update in two passes:

    ;WITH t1 AS (SELECT id,price,relatedid FROM trans)

    UPDATE trans

    SET price=(

    SELECT AVG(price)

    FROM t1

    WHERE t1.id<=trans.id

    )

    WHERE relatedid IS NULL

    ;WITH t1 AS (SELECT id,price,relatedid FROM...

  • RE: going crazy with update statement! Plz help

    John Mitchell-245523 (4/13/2011)


    Please will you post your actual update statement, since the one you posted has two syntax errors in it.

    Thanks

    John

    Thank u John... I just edited it a couple ago......

  • RE: going crazy with update statement! Plz help

    Manish_ (4/13/2011)


    I tried to execute your update statement in SQL 2005 and '=<' is not working on that hence I modified to '<=' as follows.

    Update TempTrans

    set price=(case when relatedid is...

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