• Shadab Shah (9/2/2012)


    dwain.c (9/2/2012)


    Why don't you just use UPDATE (if all 31 rows are present) or MERGE (if they are not)?

    But that means i have to write update 31 times. Can't this be eliminated by some means

    No it does not. You'd need to do something like this:

    ;WITH MyNewData (a,b,c) AS (

    SELECT 1, 2, 3

    UNION ALL SELECT 2, 3, 4

    -- etc. for 28 more records

    UNION ALL SELECT 31, 4, 5)

    UPDATE t

    SET b=d.b -- new data for column b

    ,c=d.c -- new data for column c

    FROM MyTable t

    INNER JOIN MyNewData d

    ON d.a = t.a

    My column "a" is your "CDate."


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St