Comparing Two tables with 300k records and update one table

Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
Column B has same data in both the tables.
I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
I m trying to do using PLSQL Tables.
Any suggestion?
Thanks.

Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results  will be the contents of the changed table(s) when everything is finished.
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
Column B has same data in both the tables.
I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
I m trying to do using PLSQL Tables.
Any suggestion?
Thanks.
Why are you trying to use PL/SQL tables?  If tabl_1 and tabl_2 are regular database tables, it will be much simpler and faster just to use them.
Depending on your requirements, you can do an UPDATE or MERGE, either in SQL or in PL/SQL.

Similar Messages

  • I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY WUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ??

    I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY QUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM .I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ?? HOW IT IS ??

    Hi Kishore,
    First identify deleted records by selecting "Detect deleted rows from comparison table" feature in Table Comparison
    Then Use Map Operation with Input row type as "delete" and output row type as "delete" to delete records from target table.

  • Compare 45 columns and update one table col

    I am using Oracle 9i database.I need to compare each record between two tables
    and update the one of table column (what records are updated)
    CURSOR cur1 is select t1., t2. from t1, t2 where t1.primarykey = t2.primarykey
    FOR rec1 IN cur1
    LOOP
    IF rec1.t1_col_1<>rec1.t2_col_1
    then
    update t1
    set col_t1.rem="MOdified",t.col_1=rec1.t2_col_1
    where t1.primerykey=rec1.primarykey
    END IF;
    IF rec1.t1_col_2<>rec1.t2_col_2
    then
    update t1
    set col_t1.rem="MOdified",t.col_2=rec1.t2_col_2
    where t1.primerykey=rec1.primarykey
    END IF;
    ..........45 if else conditions
    END LOOP;
    I have 1 million records to compare and 45 columns to compare, how do I increase performance.
    Currently it takes about 5hrs for the cursor to go through this if -else comparison.
    Thanks and Regards
    Swayamprakash.Chiluveru

    Hi Swayamprakash,
    Few basics first.
    1. DML SQL's perform better than PL/SQL. Sounds great but Oracle then need to hop between SQL and PL/SQL engine for every record in the cursor causing THRASHING. This is an old concept, reference of which can be found in Operating Systems.
    With Bulk Collect option, this could be minimized to a large extent, but causes a large amount of Undo being generated. This is another pitfall of using Bulk Collect. Morever, when you expect more percentage of records to be updated, it is advisable that the indices (if any) must be disabled. They can be rebuild afterwards causing very minimal amount of Undo. Performance gain is expected here.
    Now a query that you need to clarify:
    1. One million records to be updated on a diurnal basis - An OLTP database might need this functionality which is better handled by a screen driven interface rather than a SQL/Procedure running in background.
    An OLAP database must simply ignore such requirements for they are meant to be history archives.
    Suggestion:
    Merge - Seems to be the only optimal solution at the moment for the exact requirements are unclear. Already, somone has suggested this.
    Oracle Developers, DBA's must setp out from technicalities and turn towards functionality.
    Kind regards,
    Abhijit

  • Check two columns and update other table

    HI ,
    I have a table called trackCenterline .Below is the table.
    What i want to do is If the segmentSequenceID is 1 it should pick the corresponding SegmentID i.e 10001 and Check for the same segment id in other table called TrackSegment which is below.  and pick the BeginMilepost of that segmentID and Update That
    Milepost in a new table .At end SegmentSequenceID number it should pick ENDMilepost and update
    TrackCenterline table.
    TrackSegment table
    In the below table for 10001 SegmentID it should pick BeginMilepost. For end Number of SegmentSequenceID in above table ID ends at 121 for that end sequenceID It should refer TrackSegment table below and pick EndMilepost and should be updated in another
    table Milepost column.
    after that a new segment starts with new sequence .and so on ...
    bhavana

    Hi Deepa_Deepu,
    According to your description, since the issue regards T-SQL. I will help you move the question in the T-SQL forums at
    http://social.technet.microsoft.com/Forums/en-US/home?forum=transactsql. It is appropriate and more experts will assist you.
    When you want to check two columns from two tables then return some results and update the third table. I recommend you use join function and combine two tables, then use update select from statement for modifying the Mailpost table. You can refer to the
    following T-SQL Statement.
    -----using join to connect to two tables
    select TrackCenterline.FeatureId,TrackCenterline.SegmentId,
    TrackCenterline.SegmentSequenceId,TrackSegment.BeginMilepost,TrackSegment.EndMilepost
    from dbo.TrackCenterline join dbo.TrackSegment
    on TrackCenterline.SegmentId=TrackSegment.SegmentId
    order by TrackCenterline.SegmentId, TrackCenterline.SegmentSequenceId
    ---the result shows as following.
    FeatureId SegmentId SegmentSequenceId BeginMilepost EndMilepost
    AMK100011 10001 1 61.0000 61.3740
    AMK100012 10001 2 61.0000 61.3740
    AMK100013 10001 3 61.0000 61.3740
    AMK1000121 10001 121 61.0000 61.3740
    AMK100021 10002 1 61.1260 61.7240
    AMK100023 10002 3 61.1260 61.7240
    AMK100033 10003 3 61.3740 62.9530
    -----Then you can use update select from statement to modify the Mailpost table, Or you can post the table structure of Mailpost
    And for more information, you can review the following article about update statement.
    http://www.techonthenet.com/sql/update.php
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • IPod updates 2 touch with the new software, and from the update they are not connected with Time phase. They appear calling but never they enter the calls. I make calls with other users and if one connects but in these two not from the update

    iPod updates 2 touch with the new software, and from the update they are not connected with Time phase. They appear calling but never they enter the calls. I make calls with other users and if one connects but in these two not from the update

    I use Firefox 95% of the time, and there's no problem with flash content (and I'm still at .55 - downloaded .64 last week but I haven't got round to making the change yet). At the rate they've been changing it recently it may well be out of date already .
    I've been trying it in Safari, too with no problems apart from You Tube, but that's because I'm blocking Google cookies.
    One thought does occur - if your Flash preferences are set to block all Local Storage, it may be that the problem site is trying to use Flash cookies (LSOs). I had this problem recently with the BBC iPlayer streaming content. Little Snitch notified an attempt to connect to a new URL - emp.bbci.co.uk.
    If I disallowed it, no streaming; when I allowed the connection, it still wouldn't stream, so I did a bit of digging and came to the conclusion that it was trying to set a Flash cookie. When I unblocked, lo and behold - streaming resumed as normal.
    I now have LSOs blocked in a more subtle way that lets the site think it's being set (but it ain't) and the streaming still works.
    As for permissions repair - always repair from local; the permissions on the original disc will have been superceded by updates and new installations of Apple software.
    DU needs to be reading the packages on the HD, not the (now out of date) install disc.
    The recurring repair messages are normal and don't mean anything's wrong. As long as the final message is 'repair complete' there's no need to dwell on it.
    http://support.apple.com/kb/TS1448 (for Leopard and Snow Leopard - Lion no doubt has it's own set).

  • I need some working examples with pl/sql records and pl/sql tables.

    i am new to pl/sql tables and pl/sql records. i need some working examples on pl/sql records and pl/sql tables from basics to hoghlevel.how to use then procedures and functions and packages.

    i am new to pl/sql tables and pl/sql records. i need some working examples on pl/sql records and pl/sql tables from basics to hoghlevelThere is no such thing as PL/SQL "+tables+". This is a misnomer and creates the perception that a PL/SQL "table" is somewhat like a SQL table. Nothing can be further from the truth. The correct term is "+collection+" or "+associative array+". Compared to SQL tables, these are very primitive structures, very rigid structures, cannot scale, and can be quite expensive memory wise.
    That is not to say do not use an associative array or collection. These are very useful tools.. but only when applied correctly. Like using a collection for a bulk fetch to transfer more rows between the PL and SQL engines and thus decrease context switching.
    Unfortunately, quite often we see the row-by-row and slow-by-slow approach - where the developer uses SQL as an I/O only layer, pulls rows into expensive PL engine memory into record structures and arrays, and then process the rows there.
    So before looking at working example (even the wrong approach's code will compile and run and work in practice), make sure that you know the fundamentals of correctly using the PL engine and correctly using the SQL engine. And these fundamentals can be summed up into a very basic rule:
    Maximize SQL. Minimize PL/SQL+
    Get this rule right, and you will have a sound foundation for writing performant and scalable Oracle applications.

  • How to select and duplicate the records and update some column values using cursor

    I have a table with 920 records, we need to update the end date to 6/30/2014 for 920 records and I need to create all 920 records with start date is 7/1/2014 and update the external value to
    CCC.
    Note: the table primary key is not auto increment, but I have sp to get the latest key for that.
    Existing table.  
    ID
    Source Name
    Internal value
    External value
    Start date
    End date
    1
    XXX
    AAA
    BBB
    1/1/2013
    6/30/2015
    Create new records
    ID
    Source Name
    Internal value
    External value
    Start date
    End date
    921
    XXX
    AAA
    CCC
    7/1/2013
    12/30/2015

    Hi ManuGT
    If I understand what you need then you ask for:
    1. updating all current rows (920 rows in the table now)
    2. insert new rows which are duplicates of the preiviews rows, but with value 'CCC' insteade of 'BBB'
    If so, there is not reason to use a cursor and it is highly NOT RECOMMENDED to use ant type of loop.
    You should work with SET and do it all in 2 simple queries:
    -- first we duplicate the existing rows,
    -- but we use the values 'CCC" and '20140107' for the new rows values
    INSERT test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    select SourceName, 'CCC', ExternalValue, '20140107' , EndDate
    from test
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Now we update the old rows (check the filter! I get only the old rows since I filter the new rown out)
    UPDATE test
    SET EndDate = '20140107' -- I use date in format yyyymmdd, You can use other formats as well
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    Unfortunately you did not post DDL+DML! Therefore we cant see your table structure and the data sample and we can only guess. I used Saeid's post as the basic DDL+DML.
    Please next time post DDL+DML
    here is the full code with the DDL+DML that i used:
    -- This is our DDL - A create table query:
    create table test
    ( id int identity(1,1) primary key,
    SourceName nvarchar(3),
    InternalValue nvarchar(3),
    ExternalValue nvarchar(3),
    StartDate date,
    EndDate date
    go
    -- This is our DML - A query that insert some sample data
    declare @i int = 1 ;
    while @i < 921
    begin
    insert test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    values ('XXX', 'AAA', 'BBB', '1/1/2014', '6/30/2014' ) ;
    set @i += 1 ;
    end ;
    GO
    -- Here is the solution for the problem as I understood your needs:
    -- first we duplicate the existing rows,
    -- but we use the values 'CCC" and '20140107' for the new rows values
    INSERT test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    select SourceName, 'CCC', ExternalValue, '20140107' , EndDate
    from test
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Now we update the old rows (check the filter! I get only the old rows since I filter the new rown out)
    UPDATE test
    SET EndDate = '20140107' -- I use date in format yyyymmdd, You can use other formats as well
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Here we just check how the result look like :-)
    select *
    from test ;
    -- And since we do not realy need this table in our server... Here we clean the DDL (you probaby DO NOT WANT TO EXECUTE THIS!)
    DROP table test
    GO
    I hope this was useful :-)
    [Personal Site] [Blog] [Facebook]

  • Updating one table with mult. table where clause

    I'm having problems with my update statement. I want to update one table that has a mulitple table where clause. Not sure how to accomplish this. Here is what I have so far.
    update lawson.apvenmast a
    set vendor_status = 'I'
    where ((select * from apinvoice i
    where i.due_date <= TO_DATE('20011231', 'YYYYMMDD') and
    i.vendor = a.vendor)
    ((apvenmast.ven_class = 'INS') or
    (apvenmast.ven_class = 'REF')));
    Am I on the right track?
    thanks in advance for any help.
    Lisa Mears

    A lot is missing.
    where ((select * from apinvoice iA where clause should be like
    where <something> IN (select <something> from ...)
    ((apvenmast.ven_class = 'INS') or
    (apvenmast.ven_class = 'REF')));Where does this belong? There is no AND or OR with these two lines.
    Check your table aliases too.

  • Deleting and updating database table

    hi all,
    i have to update the database table based on my internal table(both having same structure).
    my database has 2 records having a key field 1 and 2 respectively.(2 records)
    and my internal table has records with key fields 3, 4 and 5 respectively(3 records) .
    i want to delete all data from database table first..
    then i want to insert all the three records in the database table..
    finally i want my database to have 3 records with key fields 3, 4 and 5 respectively that are in the internal table
    what should be the correct way?

    Hi ,
    to delete all the records from dbtab
    DELETE dbtab.
    to update the database by using internal table
    -MODIFY dbtab       FROM TABLE itab.
    but as per my knowledge structures of internal table and database table should be same
    if the database table is a Ztable please change the structure of database table as you said
    Put fields 3,4and 5 as key fields
    Thanks & Regards,
    Sateesh.

  • Analysing and Updating a table

    Hi,
    Can anyone help me on follwing query..
    Can analyse of a table and updation on to same table can happen paralley?
    thank in advance.

    What's your db version? The very first thing is that you should not use the analyze command but dbms_stats package. Now , I am not sure why you want to gather the stats and update the table at the same time? As mentioned by Erica, the update should be followed with the stats gathering. And about the index usage, there are couple of things that can stop index from being used, for example, low selectivity on the column can very well stop the index. Other than that, if you are accessing the column containing the index alone and the column is supposed to contain the null values, oracle would rather use a FTS than using the index which actually makes perfect sense since use of index would result in incorrect data. So there can be couple of htings possible which may stop your index from being used. All what dbms_stats(and even Analyze) command would do , is to make the distribution of the data known tooracle. Having stats alone doesn't guarantee that the index would be used for sure.
    HTH
    Aman....

  • Crystal 2011 linking table with a String and a Number

    Hello,
    I am able to retrieve the data I want with the following  SQL Query in SQL: If I try to create it in Crystal 2011 APPLRUNN is a string and CNTBTCH is a number. Is there a way I can link these two fields if one is a string and the other is a number ?
    SELECT   
    ENADV.APPLRUNN, ENPBD.CNTBTCH,
    ENPBD.DOCNBR
    FROM       
    ENADV INNER JOIN
    ENPBD ON ENADV.APPLRUNN = ENPBD.CNTBTCH
    Thanks,
    Debbie

    Hi Debbie,
    You cannot linking  table with a string and a number. I have given a example query:
    SELECT   
    ENADV.APPLRUNN, ENPBD.CNTBTCH,
    ENPBD.DOCNBR
    FROM       
    ENADV INNER JOIN
    ENPBD ON
    ENADV.APPLRUNN = ENPBD.APPLRUNN  or ENADV.CNTBTCH = ENPBD.CNTBTCH
    I modify last sentense because one table primary key is equal to another table Foreign key i.e
    one table ID field = another table ID field or one table NAME field = another table Name field.
    Please understand my intenction and check linking fields in tables.
    Thanks,
    DJ

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

  • Compare two invoices with same distribution line count

    I am trying to pull data out of Oracle Payables - invoices for which the invoice amount ,the vendor and distribution line count is same.
    I could achieve pulling invoices with same Vendor having same amount.But finding hard to compare the counts.
    Can anyone share ideas on how to achieve this ... Tried self join but did not work.
    The query which I used is as follows :
    select invoice_num,invoice_id,invoice_amount,vendor_id,
    (select vendor_name from apps.po_vendors where vendor_id=aia.vendor_id) vendor_name,
    (select count(*) from apps.ap_invoice_distributions_all aid where aid.invoice_id=aia.invoice_id) line_count
    from apps.ap_invoices_all aia
    where invoice_amount in (select aiab.invoice_amount
    from apps.ap_invoices_all aiab
    where aiab.creation_date >='01-AUG-2012'
    and vendor_id=aia.vendor_id
    group by aiab.invoice_amount
    Having (count(aiab.invoice_amount) >1))
    and aia.creation_date >='01-AUG-2012'
    Thanks in Advance.

    I did try your query with sample records and counts are also correct plz chk the following, for me counts are correct as per your logic -
    select aia.invoice_num,aia.invoice_id,aia.invoice_amount,aia.vendor_id,
    (select vendor_name from
    (select 'XX' vendor_name, 'A' vendor_id from dual union all
    select 'XY' vendor_name, 'B' vendor_id from dual union all
    select 'XZ' vendor_name, 'C' vendor_id from dual union all
    select 'XA' vendor_name, 'D' vendor_id from dual ) po
    where vendor_id=aia.vendor_id) vendor_name,
    (select count(*) from
    (select 1 invoice_id from dual union all
    select 1 invoice_id from dual union all
    select 1 invoice_id from dual union all
    select 2 invoice_id from dual union all
    select 3 invoice_id from dual ) aid
    where aid.invoice_id=aia.invoice_id) line_count
    from
    select 10 invoice_num, 1 invoice_id,100 invoice_amount, 'A' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 11 invoice_num, 1 invoice_id,100 invoice_amount, 'A' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 12 invoice_num, 1 invoice_id,100 invoice_amount, 'A' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 13 invoice_num, 2 invoice_id,100 invoice_amount, 'B' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 14 invoice_num, 2 invoice_id,100 invoice_amount, 'B' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 15 invoice_num, 3 invoice_id,100 invoice_amount, 'C' vendor_id ,'01-SEP-2012' creation_date from dual union all
    select 16 invoice_num, 4 invoice_id,100 invoice_amount, 'D' vendor_id,'01-OCT-2012' creation_date from dual) aia
    where aia.invoice_amount in (select aiab.invoice_amount
    from
    select 10 invoice_num, 1 invoice_id,100 invoice_amount, 'A' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 11 invoice_num, 1 invoice_id,100 invoice_amount, 'A' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 12 invoice_num, 1 invoice_id,100 invoice_amount, 'A' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 13 invoice_num, 1 invoice_id,100 invoice_amount, 'B' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 14 invoice_num, 1 invoice_id,100 invoice_amount, 'B' vendor_id ,'01-AUG-2012' creation_date from dual union all
    select 15 invoice_num, 1 invoice_id,100 invoice_amount, 'C' vendor_id ,'01-SEP-2012' creation_date from dual union all
    select 16 invoice_num, 1 invoice_id,100 invoice_amount, 'D' vendor_id,'01-OCT-2012' creation_date from dual) aiab
    where aiab.creation_date >='01-AUG-2012'
    and aiab.vendor_id=aia.vendor_id
    group by aiab.invoice_amount
    Having (count(aiab.invoice_amount) >1))
    and aia.creation_date >='01-AUG-2012'
    o/p
    INVOICE_NUM,INVOICE_ID,INVOICE_AMOUNT,VENDOR_ID,VENDOR_NAME,LINE_COUNT
    10,1,100,A,XX,3
    11,1,100,A,XX,3
    12,1,100,A,XX,3
    13,2,100,B,XY,1
    14,2,100,B,XY,1
    -------

  • Help with inserting records conditionally in another table

    I need some help on this task please. I have a table with some records like so
    Table1
    Column1   Column2   Column3      Colum4
    1                 Name1    Lastname1     1,2
    2                 Name2    Lastname2     3
    3                  Name3    Lastname3     NULL
    4                  Name4    Lastname4     1,3
    So the last column, Column4 has the number of the column that the values got changed. So the values on the first row on the Columns 1 and 2 got changed. So I have to insert those values in another table and the same for the other records.
    Table2
    Column1   Column2    Column3      
    1                Name1     NULL
    2                 NULL      Lastname2
    4                 NULL      Lastname4
    Any ideas on how to accomplish this? Any ideas would be much appreciated.

    Hi
    Try below, Next time please POST DDL & DML
    select 1 Column1, 'Name1' Column2, 'Lastname1'Column3, '1,2' Colum4 into #temp union all
    select 2 , 'Name2', 'Lastname2', '3' union all
    select 3 , 'Name3' , 'Lastname3', NULL union all
    select 4, 'Name4', 'Lastname4', '1,3'union all
    select 5, 'Name4', 'Lastname4', '1'
    select 1 Column1 ,'Name1' Column2, NULL Column3 into #temp1 union all
    select 2 ,NULL ,'Lastname2' union all
    select 4, NULL, 'Lastname4'
    select Column1, Column2, Column3, Colum4 ,C2,C1 from #temp a
    --(select Column1, Column2, Column3, case when Colum4 like '%,%' OR Colum4 IS null then Colum4 else Colum4+',' end as Colum4 from #temp) a
    outer apply (select COALESCE(Column2,Column3) From #temp1 where column1 = parsename(replace(a.colum4,',','.'),1)) a1(C1)
    outer apply (select COALESCE(Column2,Column3) From #temp1 where column1 = parsename(replace(a.colum4,',','.'),2)) a2(C2)
    You can also use split function
    http://sqlperformance.com/2012/07/t-sql-queries/split-strings
    select a.*,COALESCE(a2.Column2,a2.Column3) From #temp a
    cross apply dbo.Split(Colum4,',') a1
    left outer join #temp1 a2 on a1.item=a2.Column1
    Thanks
    Saravana Kumar C

  • Can anybody tell how to compare two documents with two pointers controlled with the same mouse

    can anybody tell how to compare two documents with two pointers controlled with the same mouse ??

    I saw what I need but in a game to find the differences between two photos (two screens, two pointers controlled by one mouse), and I need a program to make the same thing   (compare a chosen files)

Maybe you are looking for