Which one is best 'CURSOR' or 'TEMP' table, to fetch multiple columns?????

  • Koen Verbeeck (11/12/2012)


    Jason-299789 (11/12/2012)


    So the simplest way to do this is a Single Update (I'm guessing at the join and update column as they are missing in your code, but it gives the general idea).

    Update Target

    Set Address2=Source.Col_Addr2

    From Table1 Target

    JOIN Table2 Sourceon Target.Address=Source.Col_Addr1

    Where

    Target.Address2!=Source.Col_Addr2

    Nice addition of the WHERE clause, didn't think about that. 🙂

    again here we have to see how thw index will play their role/response

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • Update Target

    Set Address2=Source.Col_Addr2

    From Table1 Target

    JOIN Table2 Source on Target.Address=Source.Col_Addr1

    AND Target.Address IS NOT NULL

    Where

    Target.Address2!=Source.Col_Addr2

    is it possible??????/

  • It's possible, but redundant.

    on Target.Address=Source.Col_Addr1

    AND Target.Address IS NOT NULL

    is the same as

    on Target.Address=Source.Col_Addr1

    When Target.Address is NULL, this join condition returns false, so including Target.Address IS NOT NULL won't make a difference.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • but the problem is that i dont want to update 'Target.Address ' , if it is not

    NULL .

    the checking is actually done on TARGET TABLE not in SOURCE TABLE

    So the condition is UPDATE 'target table' Address when 'Address' field in the table (target table) is empty

    i want to add that filter . wht i do ?????

  • Add the WHERE clause

    AND Target.Address IS NULL

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • ie,

    Update Target

    Set Address2=Source.Col_Addr2

    From Table1 Target

    JOIN Table2 Sourceon Target.Address=Source.Col_Addr1

    Where

    Target.Address2!=Source.Col_Addr2

    AND

    Target.Address2 IS NOT NULL

    AND

    is it?

    if i want to add more condition , can i put there???

  • If i want to add more condtion where i put the condtion

    Update Target

    Set Address2=Source.Col_Addr2

    From Table1 Target

    JOIN Table2 Source on Target.Address=Source.Col_Addr1

    Where

    Target.Address2!=Source.Col_Addr2

    AND Target.Address2 IS NOT NULL

    AND Target.TIME >= Source .TIME

    is this right?

    the condtions to update 'TARGET' table are

    1. Target.Address2 is null

    2. Target.TIME >= Source .TIME

    3. Target.Address=Source.Col_Addr1

    ????????

  • Yes, you can add more conditions there.

    By the way, your last condition should be

    AND

    Target.Address2 IS NULL

    And you need to add a space between "source" and "on".

    This link might also be helpful:

    SQL Tutorial

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Update Target

    Set Address2=Source.Col_Addr2

    From Table1 Target

    JOIN Table2 Source on Target.Address=Source.Col_Addr1

    Where

    Target.Address2!=Source.Col_Addr2

    AND Target.Address2 IS NOT NULL

    AND Target.TIME >= Source .TIME

    is this right?

    the condtions to update 'TARGET' table are

    1. Target.Address2 is null

    2. Target.TIME >= Source .TIME

    3. Target.Address=Source.Col_Addr1

    ????????

  • UPDATE Target

    SET Address2 = Source.Col_Addr2

    FROM

    Table1 Target

    INNER JOIN

    Table2 Source

    ON Target.Address=Source.Col_Addr1

    WHERE Target.Address2 != Source.Col_Addr2

    AND Target.Address2 IS NULL

    AND Target.TIME >= Source.TIME

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 10 posts - 16 through 24 (of 24 total)

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