Update query for 2 lakhs records

I have 2 tables with 3 common columns (Col1, col2,Primary). One common column name is primary (oracle key word). No indexes are used on these tables. I need to write an update query as shown below. 
Emp table
Col1       col2        primay
100         101         y
103         104         n
201         105         y
100         101         y
Dept table
Col1       col2        primay
100         101         null
103         104         null
000         656         null
Update query Result
Col1       col2        primary
100         101         y
103         104         n
Please help me.
Thanks

Update dept d
set d.primay = (select distinct e.primay from emp e where e.col1 = d.col1 and e.col2 = d.col2);
In emp table there are 100 and 101 with two entries but with same primay value. so to handle such scenarios I have taken distinct iniside select statement.
if you have a case like where in emp table col1 and col2 are same and having different primay table, then obviously you should tell which value should go and update the dept table and based on what logic.

Similar Messages

  • Query  for getting records  max  reported  timestamp and 2nd max report

    query for getting records in between
    max reported timestamp and 2nd max reported timestamp
    HERE IS ALL RESULT SET
    TIME DOMAIN
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:08:45 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:04 TOMCAT
    30:jun:2006:20:07:24 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:07:45 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    30:jun:2006:20:08:05 TOMCAT
    PD_REPORTED_TIMESTAM PD_USER
    30:jun:2006:20:08:25 TOMCAT
    30:jun:2006:20:08:25 TOMCAT
    QUERY RESULT TO COME
    TIME DOMAIN
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    Message was edited by:
    user517983

    Hi,
    can we write query like this.
    1 select pd_user,PD_REPORTED_TIMESTAMP
    2 from sp_process_detail_current spdc
    3 where host_id='DSCP02469'and pd_user='TOMCAT'
    4 and exists(
    5 select PD_REPORTED_TIMESTAMP from sp_process_detail_current
    6* having max(PD_REPORTED_TIMESTAMP)-spdc.PD_REPORTED_TIMESTAMP=0)
    SQL> /
    PD_USER PD_REPORTED_TIMESTAM
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45
    TOMCAT 30:jun:2006:20:08:45

  • Need help to solve update querry for multiple records.

    Could any of you please provide update querry for the following scenario.
    Requiremnt:
    1. Update the UNIQUE_ID of record ( same Identifier and Identifier_code
    where END_Date is not null) with the UNIQUE_ID of the record (( same  Identifier and Identifier_code
    where END_Date  is null).
    2. If More than one NULL in END_date then update UNIQUE_ID with max(EFFective_Date) of UNIQUE_ID
    Source  data
    UNIQUE_ID
    Identifier
    Identifier_code
    EFFective_Date
    END_Date
    1
    777
    abc
    2/14/2014 11:15
    2/28/2014 9:00
    1
    777
    abc
    2/21/2014 9:00
    3/7/2014 9:02
    2
    777
    abc
    2/28/2014 9:00
    3/14/2014 9:02
    2
    777
    abc
    3/7/2014 9:02
    3/14/2014 9:02
    2
    777
    abc
    3/14/2014 9:02
    NULL
    5
    888
    xyz
    2/14/2014 11:15
    2/28/2014 9:00
    5
    888
    xyz
    2/21/2014 9:00
    3/7/2014 9:02
    5
    888
    xyz
    2/28/2014 9:00
    3/14/2014 9:02
    6
    888
    xyz
    3/7/2014 9:02
    NULL
    7
    888
    xyz
    3/14/2014 9:02
    NULL
    OutPUT .
    UNIQUE_ID
    Identifier
    Identifier_code
    EFFective_Date
    END_Date
    2
    777
    abc
    2/14/2014 11:15
    2/28/2014 9:00
    2
    777
    abc
    2/21/2014 9:00
    3/7/2014 9:02
    2
    777
    abc
    2/28/2014 9:00
    3/14/2014 9:02
    2
    777
    abc
    3/7/2014 9:02
    3/14/2014 9:02
    2
    777
    abc
    3/14/2014 9:02
    NULL
    7
    888
    xyz
    2/14/2014 11:15
    2/28/2014 9:00
    7
    888
    xyz
    2/21/2014 9:00
    3/7/2014 9:02
    7
    888
    xyz
    2/28/2014 9:00
    3/14/2014 9:02
    7
    888
    xyz
    3/7/2014 9:02
    NULL
    7
    888
    xyz
    3/14/2014 9:02
    NULL
    Thanks in advance.

    Hi Vikash,
    This query will not produce results as per requirement:
    Try it with following data
    Insert into @TempTABLE values (1,777,'abc','2/14/2014 11:15','3/14/2014 9:02')
    Insert into @TempTABLE values (1,777,'abc','2/21/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (2,777,'abc','2/28/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (2,777,'abc','3/7/2014 9:02','3/14/2014 9:02')
    Insert into @TempTABLE values (2,777,'abc','3/14/2014 9:02',NULL)
    Insert into @TempTABLE values (5,888,'xyz','2/14/2014 11:15','3/14/2014 9:02')
    Insert into @TempTABLE values (5,888,'xyz','2/21/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (5,888,'xyz','2/28/2014 9:00','3/14/2014 9:02')
    Insert into @TempTABLE values (7,888,'xyz','3/7/2014 9:02',NULL)
    Insert into @TempTABLE values (6,888,'xyz','3/14/2014 9:02',NULL)
    as per the problem statement, all records having 888,'xyz' should be updated with 6 not 7 as max effective date is associated with 6 not 7.
    Ashutosh
    Nope.
    can you check the original post first. It clearly states output as having 7 as id for all the records with 888,xyz
    also your above posted sample data is different from original sample data as you've dates jumpled up for the records with ids 6 and 7
    Please see the illustration for original sample data
    --sample table for illustration
    declare @t table
    (UNIQUE_ID int,Identifier int,Identifier_code varchar(100),EFFective_Date datetime ,END_Date datetime)
    --populate original sample data
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (1, 777, N'abc', CAST(0x0000A2D200B964F0 AS DateTime), CAST(0x0000A2E0009450C0 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (1, 777, N'abc', CAST(0x0000A2D9009450C0 AS DateTime), CAST(0x0000A2E70094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2E0009450C0 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2E70094DD60 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (2, 777, N'abc', CAST(0x0000A2EE0094DD60 AS DateTime), NULL)
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2D200B964F0 AS DateTime), CAST(0x0000A2E0009450C0 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2D9009450C0 AS DateTime), CAST(0x0000A2E70094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (5, 888, N'xyz', CAST(0x0000A2E0009450C0 AS DateTime), CAST(0x0000A2EE0094DD60 AS DateTime))
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (6, 888, N'xyz', CAST(0x0000A2E70094DD60 AS DateTime), NULL)
    INSERT @t ([UNIQUE_ID], [Identifier], [Identifier_code], [EFFective_Date], [END_Date]) VALUES (7, 888, N'xyz', CAST(0x0000A2EE0094DD60 AS DateTime), NULL)
    --do the update
    UPDATE t
    SET UNIQUE_ID = MaxID
    FROM
    SELECT MAX(CASE WHEN END_DATE IS NULL THEN UNIQUE_ID END) OVER (PARTITION BY Identifier,Identifier_code) AS MaxID,UNIQUE_ID
    FROM @t
    )t
    WHERE UNIQUE_ID <> MaxID
    AND MaxID IS NOT NULL
    --now check the output
    SELECT * FROM @t
    The output is as below
    UNIQUE_ID Identifier Identifier_code EFFective_Date END_Date
    2 777 abc 2014-02-14 11:15:00.000 2014-02-28 09:00:00.000
    2 777 abc 2014-02-21 09:00:00.000 2014-03-07 09:02:00.000
    2 777 abc 2014-02-28 09:00:00.000 2014-03-14 09:02:00.000
    2 777 abc 2014-03-07 09:02:00.000 2014-03-14 09:02:00.000
    2 777 abc 2014-03-14 09:02:00.000 NULL
    7 888 xyz 2014-02-14 11:15:00.000 2014-02-28 09:00:00.000
    7 888 xyz 2014-02-21 09:00:00.000 2014-03-07 09:02:00.000
    7 888 xyz 2014-02-28 09:00:00.000 2014-03-14 09:02:00.000
    7 888 xyz 2014-03-07 09:02:00.000 NULL
    7 888 xyz 2014-03-14 09:02:00.000 NULL
    Now compare it with original output and you'll find they're the same
    UNIQUE_ID Identifier Identifier_code EFFective_Date END_Date
    2 777 abc 2/14/2014 11:15 2/28/2014 9:00
    2 777 abc 2/21/2014 9:00 3/7/2014 9:02
    2 777 abc 2/28/2014 9:00 3/14/2014 9:02
    2 777 abc 3/7/2014 9:02 3/14/2014 9:02
    2 777 abc 3/14/2014 9:02 NULL
    7 888 xyz 2/14/2014 11:15 2/28/2014 9:00
    7 888 xyz 2/21/2014 9:00 3/7/2014 9:02
    7 888 xyz 2/28/2014 9:00 3/14/2014 9:02
    7 888 xyz 3/7/2014 9:02 NULL
    7 888 xyz 3/14/2014 9:02 NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Writing OR query for fetching records

    Hi,
    I have dowloaded a custom wsdl and generated a java client from it using Jdeveloper.
    I have a method named customObject1QueryPage(QueryInputObj) which is used to query the CRM oD to fetch records.
    I have successfully queried using the above method for one condition:-
    QueryInputObj param= new QueryInputObj();
    QueryType q = new QueryType();
    q.set_value("='" + "ABC'");
    //q.set_value("LIKE 'A*'");
    param.setAccountName(q);
    customObject1QueryPage(param);
    But now I want to query using "OR" condition with multiple names in the condition and I don't know how to
    write query for that.
    SQL query would be like "Select * from table where name='ABC' OR name='PQR' OR name ='XYZ' ";
    I want to execute same query for CRM oD but have no idea how to write it.
    Can somebody please help me as soon as possible.
    Thanks.

    Hi,
    If your intent to Use OR Condition on a field with multiple Values
    say, AccountName = 'xyz' OR AccountName= 'abc' the syntax would be *(='xyz') OR (='abc')*
    say, AccountName = 'xyz' OR AccountName= 'abc' OR AccountName = 'pqr' the syntax would be *((='xyz') OR (='abc'))OR(='pqr')*
    You can find similar example under On Demand Web Service Documentation
    Regards
    Deepak H Andeli

  • Performance of update query for single column vs multiple column

    Hi All,
    I could not find any answer for this, does it ever matter in terms of performance updating single column versus multiple column in a single update query.
    For eg. table consisting of 15 columns, what would be the difference in performance when one column is update in the single query against another update query where 15 columns are updated.
    Please do keep in mind my table columns in actually could be around 150+.
    Thanks for any information provided.

    If updated columns aren´t on where clause , then the only impact of 15 columns will be a increase on redo generation, and a possible chainning row.
    So since the redo is one of the things that have a large impact, the answer is yes.
    The performance will be slower.
    Regards
    Helio Dias.
    http://heliodias.com
    OCE SQL, OCP 9i

  • How  to fire a query for every record in a table, pass values in a loop

    Hi,
    For each record in a table, I want to loop through each record and then fire a query by passing acct, product and date from this table to the where clause of the query. I would have to create a pl/sql block..The output of the query I want to spool from sql developer.
    I need the exact syntax please for doing this.. since i am new to Oracle. Just the template will be enough. I will fill in the query.
    Any help is appreciated as always..
    Regards,
    hena

    904385 wrote:
    Hi,
    For each record in a table, I want to loop through each record and then fire a query by passing acct, product and date from this table to the where clause of the query. I would have to create a pl/sql block..The output of the query I want to spool from sql developer.
    I need the exact syntax please for doing this.. since i am new to Oracle. Just the template will be enough. I will fill in the query.
    Any help is appreciated as always..
    Regards,
    henaHave you ever considered using a JOIN ? It does the same thing as looping through a table and applying that to the where clause of a select on a query, only much, much, much faster and without the need to write any code. SQL is a declarative language, so you specify what you want and not how to do it. It can be bit of a journey to change your thought process if you come from a procedural or object world, but once you get there it's a beautiful view.

  • Update statement for multiple records

    i have table a and table b
    common col in both the tables is emp_id
    in table b i have district_id
    which i want to update in table a.... column district_id for all the employees
    how to write update statement for this
    Edited by: user10873676 on Oct 17, 2011 8:00 AM

    Based on your current description, we have something like this...
    SQL> create table a (emp_id number)
      2  /
    Table created.
    SQL>
    SQL> create table b (emp_id number, district_id number)
      2  /
    Table created.
    SQL>
    SQL> insert into a (emp_id)
      2  select rownum from dual connect by rownum <= 10
      3  /
    10 rows created.
    SQL>
    SQL> insert into b (emp_id, district_id)
      2  select rownum, 10-rownum from dual connect by rownum <= 10
      3  /
    10 rows created.
    SQL>
    SQL> update b
      2  set district_id = 1
      3  /
    10 rows updated.
    SQL>
    SQL> select * from a;
        EMP_ID
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.
    SQL> select * from b;
        EMP_ID DISTRICT_ID
             1           1
             2           1
             3           1
             4           1
             5           1
             6           1
             7           1
             8           1
             9           1
            10           1
    10 rows selected.Which I'm sure is NOT what you want as the update on table b has nothing to do with table a, and we have no idea what the district_id should be updated with.

  • Update query for lumia 925

    Hi All,
    I'm using Lumia 925, recently got an update option for my phone and I updated it.
    Its now showing lumia black.
    But even after the update I'm not able to get the option for call+sms setting (for call block feature)
    Can someone help me with this??
    Thanks
    Aman Mehra

    Hi mehraaman,
    Kindly Update all System Apps on your phone. Follow the instruction here: WP8 System Apps.

  • Update query for a table

    Hi
    Can any body send valid update query like this:
    <sql:update var="XX">
    Update emp set name='yy', phone='1234' where id='abc'
    </sql:update>
    Thanks in Advance
    SP

    Hi
    Can any body send valid update query like this:
    <sql:update var="XX">
    Update emp set name='yy', phone='1234' where id='abc'
    </sql:update>
    Thanks in Advance
    SP

  • Single Update query for multiple tables

    Hiii ....
    I want to update Table A and Table B in a single update query can it be possible.
    it is something like i have previously done with Mysql.
    e.g ..
    UPDATE A, B set a.A=1, b.B=X where (id.A= id.B) and id=101.
    Is it possible or how can i do it, help me out.

    sorry, i am posting the mysql example agin, it is something like this
    e.g ..
    UPDATE A, B set A.a=1, B.b=X where (A.id= B.id) and A.id=101

  • Update query for large no of records

    i have a doubt regarding an update statement and performance.
    There is a table with the following fields:
    empno,ename,esal,edept..etc.,
    now consider that i want to update the field salary with null for all the employees and suppose there 10 million records...how will i do that efficiently....?

    Assuming updating the rows is the most efficient solution, write a single UPDATE statement that updates 10 million rows. 10 million rows isn't huge by today's standards. My laptop can update 10 million rows of a moderately sized table in a couple minutes at the outside.
    Justin

  • Query for next record in a multiple records display

    Hi. I have a text item whose data block displays 10 records after post query. I want to put a query on the keyboard up and down button so that when i press the up or down arrow of the keyboard, the cursor moves to the next record and executes the post query trigger. I tried using the next_record command but the cursor remains on the first record and then tries to create a new record there instead of moving to the next record outputted by the initial post query trigger. I hope you get my point. Thanks

    Hi,
    I have a text item whose data block displays 10 records after post query. <b>I want to put a query on the keyboard up and down button so that when i press the up or down arrow of the keyboard</b>, the cursor moves to the next record and executes the post query trigger. I tried using the next_record command but the cursor remains on the first record and then tries to create a new record there instead of moving to the next record outputted by the initial post query trigger. I hope you get my point. You do not have to query again for moving cursor up and down. You have to use KEY-UP and KEY-DOWN with NEXT_RECORD and PREVIOUS_RECORD built-ins. Use FIRST_RECORD and LAST_RECORD for boundary conditions.
    Regards,

  • Tunning the query for faster record retrieval

    Hi,
    I am back, now this time I donot really know in which forum I should post this query, in XML or in Oracle Developers ?
    Anyway...
    The problem is :
    I have a database with millions of record in that, I give a query based on some 4/5 parameters, and retrieve the records corresponding to that, I have added indexes in the database for faster retrieval of the same, but since the no of records returned is quite high and I planned to put a prev and next link to show only 10 records at a time, I had to get the count(*) of the number of records that match, here is the problem, since there are so many records, and count(*) doesn't consider index, it takes nearly 20-30 seconds for the retrieved list to be seen on the browser window, if I just remove that count(*), the retrieval is quite fast, but then there is no prev and next as I had linked them to count(*).
    Could some one please let me know the proper way of doing it. I am a newbie to this and I have been doing some trial and error to get my work done.
    Thanks in advance,
    Regards,
    Shanthi Rajaram

    Make sure to select the COUNT() of an indexed column (the more selective the index the better), this way the optimizer can satisfy the count query with a few IO's of the index blocks instead of a full-table scan.

  • Update Query For Hierarchy Table

    Hi All
    I have a Hierarchy table that has news categories. I want use a query than when user deactivate a category, all child category has been deactivated. For example
    1- Politics
    1-1- National Politics
    1-2- International Politics
    1-2-1- Asia
    1-2-2- Africa
    2- Economic
    If Politics has been deactivated, all child must be deactivate. (1-1, 1-2, 1-2-1, 1-2-2)
    Please help me
    With Best Regards

    This is table structure script:
    SET NUMERIC_ROUNDABORT OFF
    GO
    SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
    GO
    IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
    GO
    CREATE TABLE #tmpErrors (Error int)
    GO
    SET XACT_ABORT ON
    GO
    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    GO
    BEGIN TRANSACTION
    GO
    PRINT N'Creating schemata'
    GO
    PRINT N'Creating [dbo].[Modules]'
    GO
    CREATE TABLE [dbo].[Modules]
    [Module_ID] [int] NOT NULL,
    [ModuleName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [ModuleTitle] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Status] [int] NULL
    GO
    IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
    GO
    IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
    GO
    PRINT N'Creating primary key [PK_Modules] on [dbo].[Modules]'
    GO
    ALTER TABLE [dbo].[Modules] ADD CONSTRAINT [PK_Modules] PRIMARY KEY CLUSTERED ([Module_ID])
    GO
    IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
    GO
    IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
    GO
    PRINT N'Creating [dbo].[Categories]'
    GO
    CREATE TABLE [dbo].[Categories]
    [Category_ID] [int] NOT NULL IDENTITY(1, 1),
    [Module_ID] [int] NOT NULL,
    [ParentID] [int] NULL,
    [Name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Title] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Priority] [int] NULL,
    [ThumbnailImage] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [Status] [int] NULL
    GO
    IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
    GO
    IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
    GO
    PRINT N'Creating primary key [PK_Categories] on [dbo].[Categories]'
    GO
    ALTER TABLE [dbo].[Categories] ADD CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED ([Category_ID])
    GO
    IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
    GO
    IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
    GO
    PRINT N'Adding foreign keys to [dbo].[Categories]'
    GO
    ALTER TABLE [dbo].[Categories] ADD CONSTRAINT [FK_Categories_Modules] FOREIGN KEY ([Module_ID]) REFERENCES [dbo].[Modules] ([Module_ID])
    GO
    IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
    GO
    IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
    GO
    IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
    GO
    IF @@TRANCOUNT>0 BEGIN
    PRINT 'The database update succeeded'
    COMMIT TRANSACTION
    END
    ELSE PRINT 'The database update failed'
    GO
    DROP TABLE #tmpErrors
    GO
    This is table data
    SET NUMERIC_ROUNDABORT OFF
    GO
    SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS, NOCOUNT ON
    GO
    SET DATEFORMAT YMD
    GO
    SET XACT_ABORT ON
    GO
    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    GO
    BEGIN TRANSACTION
    -- Pointer used for text / image updates. This might not be needed, but is declared here just in case
    DECLARE @pv binary(16)
    PRINT(N'Drop constraints from [dbo].[Categories]')
    GO
    ALTER TABLE [dbo].[Categories] DROP CONSTRAINT [FK_Categories_Modules]
    PRINT(N'Add 14 rows to [dbo].[Categories]')
    GO
    SET IDENTITY_INSERT [dbo].[Categories] ON
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (1, 1, NULL, 'News', N'اخبار', 1, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (2, 2, NULL, 'Article', N'مقالات', 2, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (3, 3, NULL, 'Galleries', N'گالری', 3, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (4, 1, 1, 'Politics', N'سیاسی', 1, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (5, 1, 1, 'Economic', N'اقتصادی', 2, '', 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (6, 1, 4, 'NationalPilitics', N'سیاست داخلی', 1, '', 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (7, 1, 4, 'InternationalPolitics', N'سیاست خارجی', 2, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (8, 1, 7, 'Asia', N'آسیا', 1, '', 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (9, 1, 7, 'Europe', N'اروپا', 2, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (10, 1, 7, 'Africa', N'آفریقا', 3, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (11, 2, 2, 'Scientic', N'علمی', 1, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (12, 2, 2, 'Art', N'هنری', 2, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (13, 3, 3, 'Culture', N'فرهنگی', 1, NULL, 1)
    INSERT INTO [dbo].[Categories] ([Category_ID], [Module_ID], [ParentID], [Name], [Title], [Priority], [ThumbnailImage], [Status]) VALUES (14, 3, 3, 'Religion', N'مذهبی', 2, NULL, 1)
    SET IDENTITY_INSERT [dbo].[Categories] OFF
    PRINT(N'Add constraints to [dbo].[Categories]')
    GO
    ALTER TABLE [dbo].[Categories] ADD CONSTRAINT [FK_Categories_Modules] FOREIGN KEY ([Module_ID]) REFERENCES [dbo].[Modules] ([Module_ID])
    COMMIT TRANSACTION
    GO
    Thanks for your help

  • Update query for XMLTYPE column

    Hello everyone,
    I have inserted xml data into XMLTYPE column of my table,xml data is something like this
    <Data type="FYI">                         
    <ID xmlns="http://orcl.com">T-1-1</ID>
    <Category>FRAME</Category>
    <ProductID>1</ProductID>
    <Name xmlns="http://orcl.com">Frame </Name>
    <Type>BASIC</Type>
    <Code>INSTALL</Code>
    <NodeID>1</NodeID>
    </Data>
    Now i need to update the values inside the <Data> element,like
    ID == T-2-2
    Category == IFRAME
    ProductID == 1.1
    Name == IFRAME
    We are using oracle 10g R2.
    Please help me out how to update. It would be very thankfull for your valuble suggestions
    Thanks in advance

    <Services>
    <DataService type="FRLY">
    <ID xmlns="http://www.openapplications.org/oagis/9">T-1-1-FRLY</ID>
    <CategoryCode>FRAME</CategoryCode>
    <ProductOfferingID>1</ProductOfferingID>
    <Name xmlns="http://www.openapplications.org/oagis/9">Frame Relay</Name>
    <SubType>FRLY - BASIC</SubType>
    <ActionCode>INSTALL</ActionCode>
    <NodeID>1</NodeID>
    <Contract>
    <ID xmlns="http://www.openapplications.org/oagis/9" schemeName="Networx Universal">00000</ID>
    <Category name="Contract Type">U</Category>
    </Contract>
    <Contract>
    <Type xmlns="http://www.openapplications.org/oagis/9">Routine</Type>
    </Contract>
    <CustomerParty>
    <Location/>
    </CustomerParty>
    <ProvisioningStatus type="BillingSetup">
    <Description xmlns="http://www.openapplications.org/oagis/9">C</Description>
    </ProvisioningStatus>
    <MileStone>
    <ID xmlns="http://www.openapplications.org/oagis/9">CWD</ID>
    <Date>2007-01-29</Date>
    </MileStone>
    <ActivityStatus>
    <Code xmlns="http://www.openapplications.org/oagis/9" name="DueDate"/>
    <EffectiveDateTime xmlns="http://www.openapplications.org/oagis/9">2007-01-29T00:00:00Z</EffectiveDateTime>
    </ActivityStatus>
    <AssociatedIDs>
    <ID xmlns="http://www.openapplications.org/oagis/9">1</ID>
    </AssociatedIDs>
    <AssociatedIDs>
    <TemporaryID schemeName="OPKEY">34908</TemporaryID>
    </AssociatedIDs>
    <Location>
    <ID xmlns="http://www.openapplications.org/oagis/9">T-510092</ID>
    </Location>
    <OrderID>RequestID</OrderID>
    <Accessory>
    <ActionCode>ADD</ActionCode>
    <Description xmlns="http://www.openapplications.org/oagis/9">IBM ESERVER-XSERIES306</Description>
    <CategoryCode>5</CategoryCode>
    <InstallVendorParty>
    <Name xmlns="http://www.openapplications.org/oagis/9">MCI</Name>
    </InstallVendorParty>
    </Accessory>
    <Circuit>
    <ID xmlns="http://www.openapplications.org/oagis/9">T-1-1-FRLY</ID>
    <AssociatedIDs/>
    </Circuit>
    </DataService>
    </Services>
    This was my xml which i have inserted into DB for the column XMLTYPE.Now i need to update few values in this whole file like values of
    ID under<DataService>
    Name under <DataService>
    ID under <Contract>
    Description under <ProvisioningStatus>
    i was using the UPDATEXML query to update those it's saying i row updated but when i extract it says null.
    Please help me out to solve this problem.
    Thanks in advance.

Maybe you are looking for

  • Word processors that don't lose data?

    I'm about to get my first iPad. My wife, who goes back to the iPad 1, just lost hours of work yesterday to a corrupted file. In both our cases, the most important business-like use cases are word processing. Features we both want include:   Doesn't r

  • Please tell me  how to use adf menuTabs?

    I am using adf menuTabs in my project. What happened was I could not put any components in the menuTabs. so please give me details for how to use the menuTabs.

  • Calls sound distorted and broken up?

    Hi, currently having the same fun and games as everyone else with there new N97's, but one thing i was really let down on was the sound quality when you were on a call. Every call i have made so far regardless of who i call or where i am, it sounds v

  • WCS - controller list not fully populated

    Hi Folks, I have a WCS v.7.0.230.0 and four controllers v.7.0.235.3 (on two WiSMs).  I have a problem now where when adding/modifying guest users the controller list shows only three controllers.  I don't know when this started happening or why but n

  • EP 7.0 SP 9 Upgrade

    Hi All We have isntalled EP 7.0 as usage type on NW 7.0 (SP 9) Java only. We are plannig to updgrade to higher SP level. The one which is available is 16  and should we need to go for it or stay with any other stable lower SP. Also I am confused with