Convert 1 row, multiple (identical) columns into 1 column, multiple rows

I have 10g, so unpivot is unavailable to me. I have a query that looks like:
with data as (
select 1,2,3 from dual
) select * from data
which returns 1,2,3. I need it to return:
1
2
3 and be able to name the output column. The results of this will be used in a sub-select in an IN clause. This is a trivial example. In reality the list of numbers will be varied and large - too many to either use bind variables or to put in the IN clause as a list. Is there a simple way I'm overlooking?

Hi,
One way to unpivot is to join to a table that has as many rows as you need. Instead of an actual table, you can always generate a Counter Table (actually a result set), with exactly the right number of rows. Use CASE (or something similar) go get a different column for each row of the counter table.
For example, to get the 3 columns of the scott.dept table onto 3 separate rows:
WITH     cntr     AS
     SELECT     LEVEL     AS n
     FROM     dual
     CONNECT BY     LEVEL <= 3
SELECT     CASE     c.n
         WHEN  1  THEN  TO_CHAR (d.deptno)
         WHEN  2  THEN  d.dname
         WHEN  3  THEN  d.loc
     END      AS data
FROM          scott.dept     d
CROSS JOIN     cntr          c
;Output:
DATA
10
20
30
40
ACCOUNTING
RESEARCH
SALES
OPERATIONS
NEW YORK
DALLAS
CHICAGO
BOSTON

Similar Messages

  • Identity Column in SQL Server 2000

    I am working on SBO Version 2004a.
    I created <b>Identity Column</b> in User Defined Table and made the entries for this Table and its columns in Sap Business One OUTB and CUFD tables respectivily.
    I use this identity column to populate the Code and name fields automatically using Insert triggers.
    I add 10 records to the table and now delete the 5th record. The Identity column and the code field will contain values as (1,2,3,4,6,7,8,9,10)
    Now on Upgrading the patch level( SAP Business One 2004A (6.70.190)  SP: 00  PL: 36), the Identity column is converted to simple INT column and no Identity column property is attached to it.
    There is no T-SQL in SQL 2000 to convert an existing column to Identity Column hence I can not convert it back to Identity Column.
    The Only Solution is to drop the column and re-create it as an Identity Column.
    If I do so, the Identity column is polulated for all the rows starting from 1 to 9 (seed is 1).
    Now on adding the next record, the primary key voilation occurs on the Code field since the next available Identity column value is 10 but this value is already used in 9th record.
    <b>Is there any way so that the patch do not change the definition of the User defined tables and their columns.</b>
    Thanks
    Vishal Nigam

    Hi Vishal,
    I agree with Harold. It's against SAP's support policy to allow anyone to change SBO table definitions in any way. Other SQL objects such as stored procedures or triggers will probably be unaffected by an upgrade but it is highly likely that changes to tables will be reverted and may even cause the upgrade to fail.
    There is one other possible solution, depending on how you are using the table. It is to create your own table in SQL, i.e. a table in the SBO company database but which is not a user-defined table. SBO itself will be totally unaware of the table but you could read and write to it via code (if you have written an add-on).
    Kind Regards,
    Owen

  • Error inserting a row into a table with identity column using cfgrid on change

    I got an error on trying to insert a row into a table with identity column using cfgrid on change see below
    also i would like to use cfstoreproc instead of cfquery but which argument i need to pass and how to use it usually i use stored procedure
    update table (xxx,xxx,xxx)
    values (uu,uuu,uu)
         My component
    <!--- Edit a Media Type  --->
        <cffunction name="cfn_MediaType_Update" access="remote">
            <cfargument name="gridaction" type="string" required="yes">
            <cfargument name="gridrow" type="struct" required="yes">
            <cfargument name="gridchanged" type="struct" required="yes">
            <!--- Local variables --->
            <cfset var colname="">
            <cfset var value="">
            <!--- Process gridaction --->
            <cfswitch expression="#ARGUMENTS.gridaction#">
                <!--- Process updates --->
                <cfcase value="U">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                    <cfquery datasource="#application.dsn#">
                    UPDATE SP.MediaType
                    SET #colname# = '#value#'
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <!--- Process deletes --->
                <cfcase value="D">
                    <!--- Perform actual delete --->
                    <cfquery datasource="#application.dsn#">
                    update SP.MediaType
                    set Deleted=1
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <cfcase value="I">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                   <cfquery datasource="#application.dsn#">
                    insert into  SP.MediaType (#colname#)
                    Values ('#value#')              
                    </cfquery>
                </cfcase>
            </cfswitch>
        </cffunction>
    my table
    mediatype:
    mediatypeid primary key,identity
    mediatypename
    my code is
    <cfform method="post" name="GridExampleForm">
            <cfgrid format="html" name="grid_Tables2" pagesize="3"  selectmode="edit" width="800px" 
            delete="yes"
            insert="yes"
                  bind="cfc:sp3.testing.MediaType.cfn_MediaType_All
                                                                ({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
                  onchange="cfc:sp3.testing.MediaType.cfn_MediaType_Update({cfgridaction},
                                                {cfgridrow},
                                                {cfgridchanged})">
                <cfgridcolumn name="MediaTypeID" header="ID"  display="no"/>
                <cfgridcolumn name="MediaTypeName" header="Media Type" />
            </cfgrid>
    </cfform>
    on insert I get the following error message ajax logging error message
    http: Error invoking xxxxxxx/MediaType.cfc : Element '' is undefined in a CFML structure referenced as part of an expression.
    {"gridaction":"I","gridrow":{"MEDIATYPEID":"","MEDIATYPENAME":"uuuuuu","CFGRIDROWINDEX":4} ,"gridchanged":{}}
    Thanks

    Is this with the Travel database or another database?
    If it's another database then make sure your columns
    allow nulls. To check this in the Server Navigator, expand
    your DataSource down to the column.
    Select the column and view the Is Nullable property
    in the Property Sheet
    If still no luck, check out a tutorial, like Performing Inserts, ...
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp
    John

  • How to convert a row into a column with the row headers displayed as column in javaFx?

    How do in convert a row of data into column of data to display as shown below:
    Column1|Column2|Column3|Column4
    C1          | C2          | C3           |  C4
    C5          | C6          | C7           |  C8
    How to convert the above default behavior to as below
    Column1| C1 | C5
    Column2| C2 | C6
    Column3| C3 | C7
    Column4| C4 | C8

    .

  • Convert one row to multiple column dynamic in smartform

    i want to convert on row to multiple column in smartform.As number of column is not per define..Please suggest the way out in smartform

    I saw a post and working perfect. The link is given below.
    http://scn.sap.com/community/abap/blog/2013/10/06/the-case-of-dynamic-columns-in-smartform
    Thanks to Eitan.

  • Instead of Insert, Verify not inserting into identity column.

    I am writing an Instead of Insert trigger. I would like to fire an error when inserting into an 'Identity' column.  Since UPDATE([ColumnName]) always returns TRUE for insert statements, is there an easy/fast way around this? I don't
    want to use: 
    IF(EXISTS(SELECT [i].[AS_ID] FROM [inserted] [i] WHERE [i].[AS_ID] IS NULL))
    here is my pseudo-code...
    CREATE VIEW [org].[Assets]
    WITH SCHEMABINDING
    AS
    SELECT
    [AS].[AS_ID], -- Identity field in base table
    [AS].[Tag],
    [AS].[Name]
    FROM [org].[AS_Assets_Rewind](DEFAULT, DEFAULT, DEFAULT) [AS];
    GO
    CREATE TRIGGER [org].[Assets_Insert]
    ON [org].[Assets]
    INSTEAD OF INSERT
    AS
    BEGIN
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    -- How does this statment need to be written to throw the error?
    -- UPDATE([AS_ID]) always returns TRUE
    IF(UPDATE([AS_ID]))
    RAISERROR('INSERT into the anchor identity column ''AS_ID'' is not allowed.', 16, 1) WITH NOWAIT;
    -- Is there a faster/better method than this?
    IF(EXISTS(SELECT [i].[AS_ID] FROM [inserted] [i] WHERE [i].[AS_ID] IS NOT NULL))
    RAISERROR('INSERT into the anchor identity column ''AS_ID'' is not allowed.', 16, 1) WITH NOWAIT;
    -- Do Stuff
    END;
    -- Should error for inserting into [AS_ID] field (which is an identity field)
    INSERT INTO [org].[Assets]([AS_ID], [Tag], [Name])
    VALUES(1, 'f451', 'Paper burns'),
    (2, 'k505.928', 'Paper burns in Chemistry');
    -- No error should occur
    INSERT INTO [org].[Assets]([Tag], [Name])
    VALUES('f451', 'Paper burns'),
    ('k505.928', 'Paper burns in Chemistry');

    IDENTITY is in single quotes, maybe i should have made it italics to indicate it is not the name of the column, but a logical reference to a column that has the identity property set.
    the "_Rewind" suffix is to indicate the function "looks back into time".
    Schema design is wrong? How do you recommend creating a SQL Server 2012 database that can
    1) keep a history of data with respect to changing time and transaction time
    2) update data that does not arrive at one time, aka, I may get your name and phone number today, but your e-mail address tomorrow - we need to be able to differentiate when different data was updated.
    3) no physical deletes (due to needing to go back in time)
    FYI: 
    I have examined R. Snodgrass's, L. Rönnbäck's, and T. Johnston's bi-temporal design patterns.
    here is the DDL:
    CREATE SCHEMA [posit];
    GO
    CREATE SCHEMA [org];
    GO
    CREATE TABLE [posit].[PO_Positor]
    [PO_PositorId] INT NOT NULL IDENTITY(1, 1),
    [PO_PositorApp] NVARCHAR(128) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorApp] DEFAULT(APP_NAME()),
    CONSTRAINT [CL__PO_Positor_PO_PositorApp] CHECK([PO_PositorApp] <> ''),
    [PO_PositorName] NVARCHAR(128) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorName] DEFAULT(SUSER_SNAME()),
    CONSTRAINT [CL__PO_Positor_PO_PositorName] CHECK([PO_PositorName] <> ''),
    [PO_PositorHost] NVARCHAR(128) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorHost] DEFAULT(HOST_NAME()),
    CONSTRAINT [CL__PO_Positor_PO_PositorHost] CHECK([PO_PositorHost] <> ''),
    [PO_PositorSID] VARBINARY(85) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorSID] DEFAULT(SUSER_SID()),
    [PO_PositorUID] INT NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorUID] DEFAULT(SUSER_ID()),
    [PO_PositorNote] VARCHAR(348) NULL CONSTRAINT [CL__PO_Positor_PO_PositorNote] CHECK([PO_PositorNote] <> ''),
    [PO_PositorInserted] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__PO_Positor_PO_PositorInserted] DEFAULT(SYSDATETIMEOFFSET()),
    [PO_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__PO_Positor_PO_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
    CONSTRAINT [UX__PO_Positor_PO_RowGuid] UNIQUE NONCLUSTERED([PO_RowGuid]),
    CONSTRAINT [PK__PO_Positor] PRIMARY KEY ([PO_PositorId] ASC),
    CONSTRAINT [UK__PO_Positor] UNIQUE CLUSTERED ([PO_PositorApp] ASC, [PO_PositorHost] ASC, [PO_PositorUID] ASC)
    GO
    CREATE PROCEDURE [posit].[Insert_Positor]
    @PositorNote NVARCHAR(348) = NULL
    AS
    BEGIN
    DECLARE @ProcedureDesc NVARCHAR(261) = N'[' + OBJECT_SCHEMA_NAME(@@PROCID) + N'].[' + OBJECT_NAME(@@PROCID) + N']';
    SET @PositorNote = COALESCE(@PositorNote, N'Automatically created by: ' + @ProcedureDesc);
    DECLARE @Id TABLE
    [Id] INT NOT NULL
    INSERT INTO [posit].[PO_Positor]([PO_PositorNote])
    OUTPUT [inserted].[PO_PositorId]
    INTO @Id([Id])
    VALUES (@PositorNote);
    RETURN (SELECT TOP 1 [i].[Id] FROM @Id [i]);
    END;
    GO
    CREATE PROCEDURE [posit].[Return_PositorId]
    AS
    BEGIN
    DECLARE @PositorId INT = [posit].[Get_PositorId]();
    IF (@PositorId IS NULL)
    BEGIN
    DECLARE @ProcedureDesc NVARCHAR(261) = N'[' + OBJECT_SCHEMA_NAME(@@PROCID) + N'].[' + OBJECT_NAME(@@PROCID) + N']';
    DECLARE @PositorNote NVARCHAR(348) = N'Automatically created by: ' + @ProcedureDesc;
    EXECUTE @PositorId = [posit].[Insert_Positor] @PositorNote;
    END;
    RETURN @PositorId;
    END;
    GO
    CREATE FUNCTION [posit].[Get_PositorId]
    RETURNS INT
    AS
    BEGIN
    DECLARE @PositorId INT = NULL;
    SELECT TOP 1
    @PositorId = [p].[PO_PositorId]
    FROM
    [posit].[PO_Positor] [p]
    WHERE [p].[PO_PositorApp] = APP_NAME()
    AND [p].[PO_PositorHost] = HOST_NAME()
    AND [p].[PO_PositorUID] = SUSER_ID();
    RETURN @PositorId;
    END;
    GO
    CREATE TABLE [org].[AS_Assets]
    [AS_ID] INT NOT NULL IDENTITY(1, 1),
    [AS_PositedBy] INT NOT NULL CONSTRAINT [DF__AS_Assets_PositedBy] DEFAULT([posit].[Get_PositorId]())
    CONSTRAINT [FK__AS_Assets_PositedBy] REFERENCES [posit].[PO_Positor]([PO_PositorId]),
    [AS_PositedAt] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__AS_Assets_PositedAt] DEFAULT(SYSDATETIMEOFFSET()),
    [AS_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__AS_Assets_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
    CONSTRAINT [UX__AS_Assets_RowGuid] UNIQUE([AS_RowGuid]),
    CONSTRAINT [PK__AS_Assets] PRIMARY KEY CLUSTERED ([AS_ID] ASC)
    GO
    CREATE TABLE [org].[AS_NME_Assets_Name_Posit]
    [AS_NME_ID] INT NOT NULL IDENTITY(1, 1),
    [AS_NME_AS_ID] INT NOT NULL CONSTRAINT [FK__AS_NME_Assets_Name_Posit_AS_NME_AS_ID] REFERENCES [org].[AS_Assets]([AS_ID]),
    [AS_NME_AssetTag] VARCHAR(12) NOT NULL CONSTRAINT [CL__AS_NME_Assets_Name_Posit_AS_NME_AssetTag] CHECK([AS_NME_AssetTag] <> ''),
    [AS_NME_AssetName] NVARCHAR(24) NOT NULL CONSTRAINT [CL__AS_NME_Assets_Name_Posit_AS_NME_AssetName] CHECK([AS_NME_AssetName] <> ''),
    [AS_NME_AssetDetail] NVARCHAR(48) NOT NULL CONSTRAINT [CL__AS_NME_Assets_Name_Posit_AS_NME_AssetDetail] CHECK([AS_NME_AssetDetail] <> ''),
    [AS_NME_Checksum] AS BINARY_CHECKSUM([AS_NME_AssetTag], [AS_NME_AssetName], [AS_NME_AssetDetail])
    PERSISTED NOT NULL,
    [AS_NME_ChangedAt] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__AS_NME_Assets_Name_Posit_ChangedAt] DEFAULT(SYSDATETIMEOFFSET()),
    [AS_NME_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__AS_NME_Assets_Name_Posit_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
    CONSTRAINT [UX__AS_NME_Assets_Name_Posit_RowGuid] UNIQUE NONCLUSTERED([AS_NME_RowGuid]),
    CONSTRAINT [PK__AS_NME_Assets_Name_Posit] PRIMARY KEY([AS_NME_ID] ASC),
    CONSTRAINT [UK__AS_NME_Assets_Name_Posit] UNIQUE CLUSTERED([AS_NME_AS_ID] ASC, [AS_NME_ChangedAt] DESC, [AS_NME_Checksum] ASC)
    WITH (FILLFACTOR = 95)
    GO
    CREATE TABLE [org].[AS_NME_Assets_Name_Annex]
    [AS_NME_ID] INT NOT NULL CONSTRAINT [FK__AS_NME_Assets_Name_Annex_AS_NME_ID] REFERENCES [org].[AS_NME_Assets_Name_Posit]([AS_NME_ID]),
    [AS_NME_PositedBy] INT NOT NULL CONSTRAINT [DF__AS_NME_Assets_Name_Annex_PositedBy] DEFAULT([posit].[Get_PositorId]())
    CONSTRAINT [FK__AS_NME_Assets_Name_Annex_PositedBy] REFERENCES [posit].[PO_Positor]([PO_PositorId]),
    [AS_NME_PositedAt] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__AS_NME_Assets_Name_Annex_PositedAt] DEFAULT(SYSDATETIMEOFFSET()),
    [AS_NME_PositReliability] TINYINT NOT NULL CONSTRAINT [DF__AS_NME_Assets_Name_Annex_PositRel] DEFAULT(50),
    [AS_NME_PositReliable] AS CONVERT(BIT, CASE WHEN [AS_NME_PositReliability] > 0 THEN 1 ELSE 0 END)
    PERSISTED NOT NULL,
    [AS_NME_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__AS_NME_Assets_Name_Annex_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
    CONSTRAINT [UX__AS_NME_Assets_Name_Annex_RowGuid] UNIQUE NONCLUSTERED([AS_NME_RowGuid]),
    CONSTRAINT [PK__AS_NME_Assets_Name_Annex] PRIMARY KEY CLUSTERED([AS_NME_ID] ASC, [AS_NME_PositedAt] DESC, [AS_NME_PositedBy] ASC)
    WITH (FILLFACTOR = 95)
    GO
    CREATE TABLE [org].[AS_GEO_Assets_Location_Posit]
    [AS_GEO_ID] INT NOT NULL IDENTITY(1, 1),
    [AS_GEO_AS_ID] INT NOT NULL CONSTRAINT [FK__AS_GEO_Assets_Location_Posit_AS_GEO_AS_ID] REFERENCES [org].[AS_Assets]([AS_ID]),
    [AS_GEO_Longitude_Deg] DECIMAL(17, 14) NOT NULL CONSTRAINT [CR__AS_GEO_Assets_Location_Posit_Longitude_Deg_L] CHECK([AS_GEO_Longitude_Deg] >= -180.0),
    CONSTRAINT [CR__AS_GEO_Assets_Location_Posit_Longitude_Deg_U] CHECK([AS_GEO_Longitude_Deg] <= 180.0),
    [AS_GEO_Latitude_Deg] DECIMAL(17, 14) NOT NULL CONSTRAINT [CR__AS_GEO_Assets_Location_Posit_Latitude_Deg_L] CHECK([AS_GEO_Latitude_Deg] >= -90.0),
    CONSTRAINT [CR__AS_GEO_Assets_Location_Posit_Latitude_Deg_U] CHECK([AS_GEO_Latitude_Deg] <= 90.0),
    [AS_GEO_Wgs84] AS geography::STPointFromText('POINT(' + CONVERT(VARCHAR(19), [AS_GEO_Longitude_Deg], 0) + ' ' + CONVERT(VARCHAR(19), [AS_GEO_Latitude_Deg], 0) + ')', 4326),
    [AS_GEO_Checksum] AS BINARY_CHECKSUM([AS_GEO_Longitude_Deg], [AS_GEO_Latitude_Deg])
    PERSISTED NOT NULL,
    [AS_GEO_ChangedAt] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__AS_GEO_Assets_Location_Posit_ChangedAt] DEFAULT(SYSDATETIMEOFFSET()),
    [AS_GEO_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__AS_GEO_Assets_Location_Posit_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
    CONSTRAINT [UX__AS_GEO_Assets_Location_Posit_RowGuid] UNIQUE NONCLUSTERED([AS_GEO_RowGuid]),
    CONSTRAINT [PK__AS_GEO_Assets_Location_Posit] PRIMARY KEY([AS_GEO_ID] ASC),
    CONSTRAINT [UK__AS_GEO_Assets_Location_Posit] UNIQUE CLUSTERED([AS_GEO_AS_ID] ASC, [AS_GEO_ChangedAt] DESC, [AS_GEO_Checksum] ASC)
    WITH (FILLFACTOR = 95)
    GO
    CREATE TABLE [org].[AS_GEO_Assets_Location_Annex]
    [AS_GEO_ID] INT NOT NULL CONSTRAINT [FK__AS_GEO_Assets_Location_Annex_AS_GEO_ID] REFERENCES [org].[AS_GEO_Assets_Location_Posit]([AS_GEO_ID]),
    [AS_GEO_PositedBy] INT NOT NULL CONSTRAINT [DF__AS_GEO_Assets_Location_Annex_PositedBy] DEFAULT([posit].[Get_PositorId]())
    CONSTRAINT [FK__AS_GEO_Assets_Location_Annex_PositedBy] REFERENCES [posit].[PO_Positor]([PO_PositorId]),
    [AS_GEO_PositedAt] DATETIMEOFFSET(7) NOT NULL CONSTRAINT [DF__AS_GEO_Assets_Location_Annex_PositedAt] DEFAULT(SYSDATETIMEOFFSET()),
    [AS_GEO_PositReliability] TINYINT NOT NULL CONSTRAINT [DF__AS_GEO_Assets_Location_Annex_PositRel] DEFAULT(50),
    [AS_GEO_PositReliable] AS CONVERT(BIT, CASE WHEN [AS_GEO_PositReliability] > 0 THEN 1 ELSE 0 END)
    PERSISTED NOT NULL,
    [AS_GEO_RowGuid] UNIQUEIDENTIFIER NOT NULL CONSTRAINT [DF__AS_GEO_Assets_Location_Annex_RowGuid] DEFAULT(NEWSEQUENTIALID()) ROWGUIDCOL,
    CONSTRAINT [UX__AS_GEO_Assets_Location_Annex_RowGuid] UNIQUE NONCLUSTERED([AS_GEO_RowGuid]),
    CONSTRAINT [PK__AS_GEO_Assets_Location_Annex] PRIMARY KEY CLUSTERED([AS_GEO_ID] ASC, [AS_GEO_PositedAt] DESC, [AS_GEO_PositedBy] ASC)
    WITH (FILLFACTOR = 95)
    GO
    CREATE FUNCTION [org].[AS_NME_Assets_Name_Posit_RW]
    @ChangedBefore DATETIMEOFFSET(7) = '9999-12-31'
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
    SELECT
    [p].[AS_NME_ID],
    [p].[AS_NME_AS_ID],
    [p].[AS_NME_AssetTag],
    [p].[AS_NME_AssetName],
    [p].[AS_NME_AssetDetail],
    [p].[AS_NME_Checksum],
    [p].[AS_NME_ChangedAt]
    FROM
    [org].[AS_NME_Assets_Name_Posit] [p]
    WHERE
    [p].[AS_NME_ChangedAt] < @ChangedBefore;
    GO
    CREATE FUNCTION [org].[AS_NME_Assets_Name_Annex_RW]
    @PositedBefore DATETIMEOFFSET(7) = '9999-12-31'
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
    SELECT
    [a].[AS_NME_ID],
    [a].[AS_NME_PositedBy],
    [a].[AS_NME_PositedAt],
    [a].[AS_NME_PositReliability],
    [a].[AS_NME_PositReliable]
    FROM
    [org].[AS_NME_Assets_Name_Annex] [a]
    WHERE[a].[AS_NME_PositedAt] < @PositedBefore;
    GO
    CREATE FUNCTION [org].[AS_NME_Assets_Name_RW]
    @ChangedBefore DATETIMEOFFSET(7) = '9999-12-31',
    @PositedBefore DATETIMEOFFSET(7) = '9999-12-31'
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
    SELECT
    [p].[AS_NME_ID],
    [p].[AS_NME_AS_ID],
    [p].[AS_NME_AssetTag],
    [p].[AS_NME_AssetName],
    [p].[AS_NME_AssetDetail],
    [p].[AS_NME_Checksum],
    [p].[AS_NME_ChangedAt],
    [a].[AS_NME_PositedBy],
    [a].[AS_NME_PositedAt],
    [a].[AS_NME_PositReliability],
    [a].[AS_NME_PositReliable]
    FROM
    [org].[AS_NME_Assets_Name_Posit_RW](@ChangedBefore) [p]
    INNER JOIN
    [org].[AS_NME_Assets_Name_Annex_RW](@PositedBefore) [a]
    ON [a].[AS_NME_ID] = [p].[AS_NME_ID]
    AND [a].[AS_NME_PositedAt] = (
    SELECT TOP 1
    [s].[AS_NME_PositedAt]
    FROM
    [org].[AS_NME_Assets_Name_Annex_RW](@PositedBefore) [s]
    WHERE [s].[AS_NME_ID] = [p].[AS_NME_ID]
    ORDER BY
    [s].[AS_NME_PositedAt] DESC
    GO
    CREATE FUNCTION [org].[AS_GEO_Assets_Location_Posit_RW]
    @ChangedBefore DATETIMEOFFSET(7) = '9999-12-31'
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
    SELECT
    [p].[AS_GEO_ID],
    [p].[AS_GEO_AS_ID],
    [p].[AS_GEO_Longitude_Deg],
    [p].[AS_GEO_Latitude_Deg],
    [p].[AS_GEO_Wgs84],
    [p].[AS_GEO_Checksum],
    [p].[AS_GEO_ChangedAt]
    FROM
    [org].[AS_GEO_Assets_Location_Posit] [p]
    WHERE
    [p].[AS_GEO_ChangedAt] < @ChangedBefore;
    GO
    CREATE FUNCTION [org].[AS_GEO_Assets_Location_Annex_RW]
    @PositedBefore DATETIMEOFFSET(7) = '9999-12-31'
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
    SELECT
    [a].[AS_GEO_ID],
    [a].[AS_GEO_PositedBy],
    [a].[AS_GEO_PositedAt],
    [a].[AS_GEO_PositReliability],
    [a].[AS_GEO_PositReliable]
    FROM
    [org].[AS_GEO_Assets_Location_Annex] [a]
    WHERE
    [a].[AS_GEO_PositedAt] < @PositedBefore;
    GO
    CREATE FUNCTION [org].[AS_GEO_Assets_Location_RW]
    @ChangedBefore DATETIMEOFFSET(7) = '9999-12-31',
    @PositedBefore DATETIMEOFFSET(7) = '9999-12-31'
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
    SELECT
    [p].[AS_GEO_ID],
    [p].[AS_GEO_AS_ID],
    [p].[AS_GEO_Longitude_Deg],
    [p].[AS_GEO_Latitude_Deg],
    [p].[AS_GEO_Wgs84],
    [p].[AS_GEO_Checksum],
    [p].[AS_GEO_ChangedAt],
    [a].[AS_GEO_PositedBy],
    [a].[AS_GEO_PositedAt],
    [a].[AS_GEO_PositReliability],
    [a].[AS_GEO_PositReliable]
    FROM
    [org].[AS_GEO_Assets_Location_Posit_RW](@ChangedBefore) [p]
    INNER JOIN
    [org].[AS_GEO_Assets_Location_Annex_RW](@PositedBefore) [a]
    ON [a].[AS_GEO_ID] = [p].[AS_GEO_ID]
    AND [a].[AS_GEO_PositedAt] = (
    SELECT TOP 1
    [s].[AS_GEO_PositedAt]
    FROM
    [org].[AS_GEO_Assets_Location_Annex_RW](@PositedBefore) [s]
    WHERE [s].[AS_GEO_ID] = [p].[AS_GEO_ID]
    ORDER BY
    [s].[AS_GEO_PositedAt] DESC
    GO
    CREATE FUNCTION [org].[AS_Assets_Rewind]
    @ChangedBefore DATETIMEOFFSET(7) = '9999-12-31',
    @PositedBefore DATETIMEOFFSET(7) = '9999-12-31',
    @Reliable BIT = 1
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
    RETURN
    SELECT
    [AS].[AS_ID],
    [AS].[AS_PositedBy],
    [AS].[AS_PositedAt],
    [NME].[AS_NME_ID],
    [NME].[AS_NME_AS_ID],
    [NME].[AS_NME_AssetTag],
    [NME].[AS_NME_AssetName],
    [NME].[AS_NME_AssetDetail],
    [NME].[AS_NME_Checksum],
    [NME].[AS_NME_ChangedAt],
    [NME].[AS_NME_PositedBy],
    [NME].[AS_NME_PositedAt],
    [NME].[AS_NME_PositReliability],
    [NME].[AS_NME_PositReliable],
    [GEO].[AS_GEO_ID],
    [GEO].[AS_GEO_AS_ID],
    [GEO].[AS_GEO_Longitude_Deg],
    [GEO].[AS_GEO_Latitude_Deg],
    [GEO].[AS_GEO_Wgs84],
    [GEO].[AS_GEO_Checksum],
    [GEO].[AS_GEO_ChangedAt],
    [GEO].[AS_GEO_PositedBy],
    [GEO].[AS_GEO_PositedAt],
    [GEO].[AS_GEO_PositReliability],
    [GEO].[AS_GEO_PositReliable]
    FROM
    [org].[AS_Assets] [AS]
    INNER JOIN
    [org].[AS_NME_Assets_Name_RW](@ChangedBefore, @PositedBefore) [NME]
    ON [NME].[AS_NME_AS_ID] = [AS].[AS_ID]
    AND [NME].[AS_NME_PositReliable] = @Reliable
    AND [NME].[AS_NME_ID] = (
    SELECT TOP 1
    [NME_s].[AS_NME_ID]
    FROM
    [org].[AS_NME_Assets_Name_RW](@ChangedBefore, @PositedBefore) [NME_s]
    WHERE [NME_s].[AS_NME_AS_ID] = [AS].[AS_ID]
    ORDER BY
    [NME_s].[AS_NME_ChangedAt] DESC,
    [NME_s].[AS_NME_PositedAt] DESC
    LEFT OUTER JOIN
    [org].[AS_GEO_Assets_Location_RW](@ChangedBefore, @PositedBefore) [GEO]
    ON [GEO].[AS_GEO_AS_ID] = [AS].[AS_ID]
    AND [GEO].[AS_GEO_PositReliable] = @Reliable
    AND [GEO].[AS_GEO_ID] = (
    SELECT TOP 1
    [GEO_s].[AS_GEO_ID]
    FROM
    [org].[AS_GEO_Assets_Location_RW](@ChangedBefore, @PositedBefore) [GEO_s]
    WHERE [GEO_s].[AS_GEO_AS_ID] = [AS].[AS_ID]
    ORDER BY
    [GEO_s].[AS_GEO_ChangedAt] DESC,
    [GEO_s].[AS_GEO_PositedAt] DESC
    GO
    CREATE VIEW [org].[AS_NME_Assets_Name_SK]
    WITH SCHEMABINDING
    AS
    SELECT
    [p].[AS_NME_ID],
    [p].[AS_NME_AS_ID],
    [p].[AS_NME_AssetTag],
    [p].[AS_NME_AssetName],
    [p].[AS_NME_AssetDetail],
    [p].[AS_NME_Checksum],
    [p].[AS_NME_ChangedAt],
    [a].[AS_NME_PositedBy],
    [a].[AS_NME_PositedAt],
    [a].[AS_NME_PositReliability],
    [a].[AS_NME_PositReliable]
    FROM
    [org].[AS_NME_Assets_Name_Posit] [p]
    INNER JOIN
    [org].[AS_NME_Assets_Name_Annex] [a]
    ON [a].[AS_NME_ID] = [p].[AS_NME_ID];
    GO
    CREATE UNIQUE CLUSTERED INDEX [PK__AS_NME_Assets_Name_SK]
    ON [org].[AS_NME_Assets_Name_SK]
    [AS_NME_AS_ID] ASC,
    [AS_NME_ChangedAt] DESC,
    [AS_NME_PositedAt] DESC,
    [AS_NME_PositedBy] ASC,
    [AS_NME_PositReliable] ASC
    WITH (FILLFACTOR = 95);
    GO
    CREATE VIEW [org].[AS_GEO_Assets_Location_SK]
    WITH SCHEMABINDING
    AS
    SELECT
    [p].[AS_GEO_ID],
    [p].[AS_GEO_AS_ID],
    [p].[AS_GEO_Wgs84],
    [p].[AS_GEO_Checksum],
    [p].[AS_GEO_ChangedAt],
    [a].[AS_GEO_PositedBy],
    [a].[AS_GEO_PositedAt],
    [a].[AS_GEO_PositReliability],
    [a].[AS_GEO_PositReliable]
    FROM
    [org].[AS_GEO_Assets_Location_Posit] [p]
    INNER JOIN
    [org].[AS_GEO_Assets_Location_Annex] [a]
    ON [a].[AS_GEO_ID] = [p].[AS_GEO_ID];
    GO
    CREATE UNIQUE CLUSTERED INDEX [PK__AS_GEO_Assets_Location_SK]
    ON [org].[AS_GEO_Assets_Location_SK]
    [AS_GEO_AS_ID] ASC,
    [AS_GEO_ChangedAt] DESC,
    [AS_GEO_PositedAt] DESC,
    [AS_GEO_PositedBy] ASC,
    [AS_GEO_PositReliable] ASC
    WITH (FILLFACTOR = 95);
    GO
    CREATE VIEW [org].[AS_Assets_Current]
    WITH SCHEMABINDING
    AS
    SELECT
    [AS].[AS_ID],
    [AS].[AS_PositedBy],
    [AS].[AS_PositedAt],
    [AS].[AS_NME_ID],
    [AS].[AS_NME_AS_ID],
    [AS].[AS_NME_AssetTag],
    [AS].[AS_NME_AssetName],
    [AS].[AS_NME_AssetDetail],
    [AS].[AS_NME_Checksum],
    [AS].[AS_NME_ChangedAt],
    [AS].[AS_NME_PositedBy],
    [AS].[AS_NME_PositedAt],
    [AS].[AS_NME_PositReliability],
    [AS].[AS_NME_PositReliable],
    [AS].[AS_GEO_ID],
    [AS].[AS_GEO_AS_ID],
    [AS].[AS_GEO_Longitude_Deg],
    [AS].[AS_GEO_Latitude_Deg],
    [AS].[AS_GEO_Wgs84],
    [AS].[AS_GEO_Checksum],
    [AS].[AS_GEO_ChangedAt],
    [AS].[AS_GEO_PositedBy],
    [AS].[AS_GEO_PositedAt],
    [AS].[AS_GEO_PositReliability],
    [AS].[AS_GEO_PositReliable]
    FROM [org].[AS_Assets_Rewind](DEFAULT, DEFAULT, DEFAULT) [AS];
    GO
    CREATE TRIGGER [org].[AS_Assets_Current_Insert]
    ON [org].[AS_Assets_Current]
    INSTEAD OF INSERT
    AS
    BEGIN
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    IF(EXISTS(SELECT [i].[AS_ID] FROM [inserted] [i] WHERE [i].[AS_ID] IS NOT NULL))
    RAISERROR('INSERT into the anchor identity column ''AS_ID'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_NME_ID] FROM [inserted] [i] WHERE [i].[AS_NME_ID] IS NOT NULL))
    RAISERROR('INSERT into the identity column ''AS_NME_ID'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_NME_AS_ID] FROM [inserted] [i] WHERE [i].[AS_NME_AS_ID] IS NOT NULL))
    RAISERROR('INSERT into the foreign key identity column ''AS_NME_AS_ID'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_NME_Checksum] FROM [inserted] [i] WHERE [i].[AS_NME_Checksum] IS NOT NULL))
    RAISERROR('INSERT into the computed column ''AS_NME_Checksum'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_NME_PositReliable] FROM [inserted] [i] WHERE [i].[AS_NME_PositReliable] IS NOT NULL))
    RAISERROR('INSERT into the computed column ''AS_NME_PositReliable'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_GEO_ID] FROM [inserted] [i] WHERE [i].[AS_GEO_ID] IS NOT NULL))
    RAISERROR('INSERT into the identity column ''AS_GEO_ID'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_GEO_AS_ID] FROM [inserted] [i] WHERE [i].[AS_GEO_AS_ID] IS NOT NULL))
    RAISERROR('INSERT into the foreign key identity column ''AS_GEO_AS_ID'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_GEO_Checksum] FROM [inserted] [i] WHERE [i].[AS_GEO_Checksum] IS NOT NULL))
    RAISERROR('INSERT into the computed column ''AS_GEO_Checksum'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_GEO_PositReliable] FROM [inserted] [i] WHERE [i].[AS_GEO_PositReliable] IS NOT NULL))
    RAISERROR('INSERT into the computed column ''AS_GEO_PositReliable'' is not allowed.', 16, 1) WITH NOWAIT;
    IF(EXISTS(SELECT [i].[AS_GEO_Wgs84] FROM [inserted] [i] WHERE [i].[AS_GEO_Wgs84] IS NOT NULL))
    RAISERROR('INSERT into the computed column ''AS_GEO_Wgs84'' is not allowed.', 16, 1) WITH NOWAIT;
    DECLARE @Reliability INT = 50;
    DECLARE @Now DATETIMEOFFSET(7) = SYSDATETIMEOFFSET();
    DECLARE @PositedBy INT;
    EXECUTE @PositedBy = [posit].[Return_PositorId];
    DECLARE @Inserted TABLE
    [AS_PositedBy] INT NOT NULL,
    [AS_PositedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_NME_AssetTag] VARCHAR(12) NOT NULL CHECK([AS_NME_AssetTag] <> ''),
    [AS_NME_AssetName] NVARCHAR(24) NOT NULL CHECK([AS_NME_AssetName] <> ''),
    [AS_NME_AssetDetail] NVARCHAR(48) NOT NULL CHECK([AS_NME_AssetDetail] <> ''),
    [AS_NME_Checksum] AS BINARY_CHECKSUM([AS_NME_AssetTag], [AS_NME_AssetName], [AS_NME_AssetDetail])
    PERSISTED NOT NULL,
    [AS_NME_ChangedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_NME_PositedBy] INT NOT NULL,
    [AS_NME_PositedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_NME_PositReliability] TINYINT NOT NULL,
    [AS_GEO_Longitude_Deg] DECIMAL(17, 14) NULL CHECK([AS_GEO_Longitude_Deg] >= -180.0), CHECK([AS_GEO_Longitude_Deg] <= 180.0),
    [AS_GEO_Latitude_Deg] DECIMAL(17, 14) NULL CHECK([AS_GEO_Latitude_Deg] >= -90.0), CHECK([AS_GEO_Latitude_Deg] <= 90.0),
    [AS_GEO_Checksum] AS BINARY_CHECKSUM([AS_GEO_Longitude_Deg], [AS_GEO_Latitude_Deg])
    PERSISTED NOT NULL,
    [AS_GEO_ChangedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_GEO_PositedBy] INT NOT NULL,
    [AS_GEO_PositedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_GEO_PositReliability] TINYINT NOT NULL,
    [ROW_ID] INT NOT NULL,
    PRIMARY KEY([ROW_ID] ASC)
    INSERT INTO @Inserted
    [AS_PositedBy],
    [AS_PositedAt],
    [AS_NME_AssetTag],
    [AS_NME_AssetName],
    [AS_NME_AssetDetail],
    [AS_NME_ChangedAt],
    [AS_NME_PositedBy],
    [AS_NME_PositedAt],
    [AS_NME_PositReliability],
    [AS_GEO_Longitude_Deg],
    [AS_GEO_Latitude_Deg],
    [AS_GEO_ChangedAt],
    [AS_GEO_PositedBy],
    [AS_GEO_PositedAt],
    [AS_GEO_PositReliability],
    [ROW_ID]
    SELECT
    COALESCE([i].[AS_PositedBy], @PositedBy),
    COALESCE([i].[AS_PositedAt], @Now),
    [i].[AS_NME_AssetTag],
    [i].[AS_NME_AssetName],
    [i].[AS_NME_AssetDetail],
    COALESCE([i].[AS_NME_ChangedAt], @Now),
    COALESCE([i].[AS_NME_PositedBy], @PositedBy),
    COALESCE([i].[AS_NME_PositedAt], @Now),
    COALESCE([i].[AS_NME_PositReliability], @Reliability),
    [i].[AS_GEO_Longitude_Deg],
    [i].[AS_GEO_Latitude_Deg],
    COALESCE([i].[AS_GEO_ChangedAt], @Now),
    COALESCE([i].[AS_GEO_PositedBy], @PositedBy),
    COALESCE([i].[AS_GEO_PositedAt], @Now),
    COALESCE([i].[AS_GEO_PositReliability], @Reliability),
    ROW_NUMBER() OVER (PARTITION BY [i].[AS_ID] ORDER BY [i].[AS_ID])
    FROM
    [inserted] [i]
    LEFT OUTER JOIN
    [org].[AS_Assets_Current] [c]
    ON [c].[AS_NME_Checksum] = BINARY_CHECKSUM([i].[AS_NME_AssetTag], [i].[AS_NME_AssetName], [i].[AS_NME_AssetDetail])
    WHERE
    [i].[AS_ID] IS NULL
    AND [i].[AS_NME_ID] IS NULL
    AND [i].[AS_NME_AS_ID] IS NULL
    AND [i].[AS_GEO_ID] IS NULL
    AND [i].[AS_GEO_AS_ID] IS NULL
    AND [c].[AS_NME_AS_ID] IS NULL;
    DECLARE @Anchor TABLE
    [ROW_ID] INT NOT NULL IDENTITY(1, 1),
    [AS_ID] INT NOT NULL,
    PRIMARY KEY([ROW_ID] ASC),
    UNIQUE CLUSTERED([AS_ID] ASC)
    INSERT INTO [org].[AS_Assets]
    [AS_PositedBy],
    [AS_PositedAt]
    OUTPUT
    [inserted].[AS_ID]
    INTO
    @Anchor
    [AS_ID]
    SELECT
    [i].[AS_PositedBy],
    [i].[AS_PositedAt]
    FROM
    @Inserted [i]
    ORDER BY
    [i].[ROW_ID] ASC;
    DECLARE @NME_Posit TABLE
    [AS_NME_ID] INT NOT NULL,
    [AS_NME_Checksum] INT NOT NULL,
    PRIMARY KEY([AS_NME_ID] ASC),
    UNIQUE CLUSTERED([AS_NME_Checksum] ASC)
    INSERT INTO [org].[AS_NME_Assets_Name_Posit]
    [AS_NME_AS_ID],
    [AS_NME_AssetTag],
    [AS_NME_AssetName],
    [AS_NME_AssetDetail],
    [AS_NME_ChangedAt]
    OUTPUT
    [inserted].[AS_NME_ID],
    [inserted].[AS_NME_Checksum]
    INTO
    @NME_Posit
    [AS_NME_ID],
    [AS_NME_Checksum]
    SELECT
    [a].[AS_ID],
    [i].[AS_NME_AssetTag],
    [i].[AS_NME_AssetName],
    [i].[AS_NME_AssetDetail],
    [i].[AS_NME_ChangedAt]
    FROM
    @Inserted [i]
    LEFT OUTER JOIN
    @Anchor [a]
    ON [a].[ROW_ID] = [i].[ROW_ID]
    WHERE [a].[AS_ID] IS NOT NULL;
    INSERT INTO [org].[AS_NME_Assets_Name_Annex]
    [AS_NME_ID],
    [AS_NME_PositedBy],
    [AS_NME_PositedAt],
    [AS_NME_PositReliability]
    SELECT
    [p].[AS_NME_ID],
    [i].[AS_NME_PositedBy],
    [i].[AS_NME_PositedAt],
    [i].[AS_NME_PositReliability]
    FROM
    @Inserted [i]
    INNER JOIN
    @NME_Posit [p]
    ON [p].[AS_NME_Checksum] = [i].[AS_NME_Checksum];
    DECLARE @GEO_Posit TABLE
    [AS_GEO_ID] INT NOT NULL,
    [AS_GEO_Checksum] INT NOT NULL,
    PRIMARY KEY([AS_GEO_ID] ASC),
    UNIQUE CLUSTERED([AS_GEO_Checksum] ASC)
    INSERT INTO [org].[AS_GEO_Assets_Location_Posit]
    [AS_GEO_AS_ID],
    [AS_GEO_Longitude_Deg],
    [AS_GEO_Latitude_Deg],
    [AS_GEO_ChangedAt]
    OUTPUT
    [inserted].[AS_GEO_ID],
    [inserted].[AS_GEO_Checksum]
    INTO
    @GEO_Posit
    [AS_GEO_ID],
    [AS_GEO_Checksum]
    SELECT
    [a].[AS_ID],
    [i].[AS_GEO_Longitude_Deg],
    [i].[AS_GEO_Latitude_Deg],
    [i].[AS_NME_ChangedAt]
    FROM
    @Inserted [i]
    LEFT OUTER JOIN
    @Anchor [a]
    ON [a].[ROW_ID] = [i].[ROW_ID]
    WHERE [a].[AS_ID] IS NOT NULL
    AND [i].[AS_GEO_Longitude_Deg] IS NOT NULL
    AND [i].[AS_GEO_Latitude_Deg] IS NOT NULL;
    INSERT INTO [org].[AS_GEO_Assets_Location_Annex]
    [AS_GEO_ID],
    [AS_GEO_PositedBy],
    [AS_GEO_PositedAt],
    [AS_GEO_PositReliability]
    SELECT
    [p].[AS_GEO_ID],
    [i].[AS_GEO_PositedBy],
    [i].[AS_GEO_PositedAt],
    [i].[AS_GEO_PositReliability]
    FROM
    @Inserted [i]
    INNER JOIN
    @GEO_Posit [p]
    ON [p].[AS_GEO_Checksum] = [i].[AS_GEO_Checksum];
    END;
    GO
    CREATE TRIGGER [org].[AS_Assets_Current_Update]
    ON [org].[AS_Assets_Current]
    INSTEAD OF UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    IF(UPDATE([AS_ID]))
    RAISERROR('Cannot update the anchor identity column ''AS_ID''.', 16, 1);
    IF(UPDATE([AS_PositedBy]))
    RAISERROR('Cannot update the anchor column ''AS_PositedBy''.', 16, 1);
    IF(UPDATE([AS_PositedAt]))
    RAISERROR('Cannot update the anchor column ''AS_PositedAt''.', 16, 1);
    IF(UPDATE([AS_NME_ID]))
    RAISERROR('Cannot update the identity column ''AS_NME_ID''.', 16, 1);
    IF(UPDATE([AS_NME_AS_ID]))
    RAISERROR('Cannot update the foreign key identity column ''AS_NME_AS_ID''.', 16, 1);
    IF(UPDATE([AS_NME_Checksum]))
    RAISERROR('Cannot update the computed column ''AS_NME_Checksum''.', 16, 1);
    IF(UPDATE([AS_NME_PositReliable]))
    RAISERROR('Cannot update the computed column ''AS_NME_PositReliable''.', 16, 1);
    IF(UPDATE([AS_GEO_ID]))
    RAISERROR('Cannot update the identity column ''AS_GEO_ID''.', 16, 1);
    IF(UPDATE([AS_GEO_AS_ID]))
    RAISERROR('Cannot update the foreign key identity column ''AS_GEO_AS_ID''.', 16, 1);
    IF(UPDATE([AS_GEO_Checksum]))
    RAISERROR('Cannot update the computed column ''AS_GEO_Checksum''.', 16, 1);
    IF(UPDATE([AS_GEO_PositReliable]))
    RAISERROR('Cannot update the computed column ''AS_GEO_PositReliable''.', 16, 1);
    IF(UPDATE([AS_GEO_Wgs84]))
    RAISERROR('Cannot update the computed column ''AS_GEO_Wgs84''.', 16, 1);
    DECLARE @Now DATETIMEOFFSET(7) = SYSDATETIMEOFFSET();
    DECLARE @PositedBy INT;
    EXECUTE @PositedBy = [posit].[Return_PositorId];
    DECLARE @Inserted TABLE
    [AS_ID] INT NOT NULL,
    [AS_PositedBy] INT NOT NULL,
    [AS_PositedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_NME_ID] INT NOT NULL,
    [AS_NME_AS_ID] INT NOT NULL,
    [AS_NME_AssetTag] VARCHAR(12) NULL CHECK([AS_NME_AssetTag] <> ''),
    [AS_NME_AssetName] NVARCHAR(24) NULL CHECK([AS_NME_AssetName] <> ''),
    [AS_NME_AssetDetail] NVARCHAR(48) NULL CHECK([AS_NME_AssetDetail] <> ''),
    [AS_NME_Checksum] AS BINARY_CHECKSUM([AS_NME_AssetTag], [AS_NME_AssetName], [AS_NME_AssetDetail])
    PERSISTED NOT NULL,
    [AS_NME_ChangedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_NME_PositedBy] INT NOT NULL,
    [AS_NME_PositedAt] DATETIMEOFFSET(7) NOT NULL,
    [AS_NME_PositReliability] TINYINT NOT NULL,
    [AS_GEO_ID] INT NULL,
    [AS_GEO_AS_ID] INT NULL,
    [AS_GEO_Longitude_Deg] DECIMAL(17, 14) NULL CHECK([AS_GEO_Longitude_Deg] >= -180.0), CHECK([AS_GEO_Longitude_Deg] <= 180.0),
    [AS_GEO_Latitude_Deg] DECIMAL(17, 14) NULL CHECK([AS_GEO_Latitude_Deg] >= -90.0), CHECK([AS_GEO_Latitude_Deg] <= 90.0),
    [AS_GEO_Checksum] AS BINARY_CHECKSUM([AS_GEO_Longitude_Deg], [AS_GEO_Latitude_Deg])
    PERSISTED NOT NULL,
    [AS_GEO_ChangedAt] DATETIMEOFFSET(7) NULL,
    [AS_GEO_PositedBy] INT NULL,
    [AS_GEO_PositedAt] DATETIMEOFFSET(7) NULL,
    [AS_GEO_PositReliability] TINYINT NULL,
    [ROW_ID] INT NOT NULL,
    PRIMARY KEY([ROW_ID] ASC)
    INSERT INTO @Inserted
    [AS_ID],
    [AS_PositedBy],
    [AS_PositedAt],
    [AS_NME_ID],
    [AS_NME_AS_ID],
    [AS_NME_AssetTag],
    [AS_NME_AssetName],
    [AS_NME_AssetDetail],
    [AS_NME_ChangedAt],
    [AS_NME_PositedBy],
    [AS_NME_PositedAt],
    [AS_NME_PositReliability],
    [AS_GEO_ID],
    [AS_GEO_AS_ID],
    [AS_GEO_Longitude_Deg],
    [AS_GEO_Latitude_Deg],
    [AS_GEO_ChangedAt],
    [AS_GEO_PositedBy],
    [AS_GEO_PositedAt],
    [AS_GEO_PositReliability],
    [ROW_ID]
    SELECT
    [i].[AS_ID],
    CASE WHEN (UPDATE([AS_PositedBy])) THEN [i].[AS_PositedBy] ELSE @PositedBy END,
    CASE WHEN (UPDATE([AS_PositedAt])) THEN [i].[AS_PositedAt] ELSE @Now END,
    [i].[AS_NME_ID],
    [i].[AS_NME_AS_ID],
    [i].[AS_NME_AssetTag],
    [i].[AS_NME_AssetName],
    [i].[AS_NME_AssetDetail],
    CASE WHEN (UPDATE([AS_NME_ChangedAt])) THEN [i].[AS_NME_ChangedAt] ELSE @Now END,
    CASE WHEN (UPDATE([AS_NME_PositedBy])) THEN [i].[AS_NME_PositedBy] ELSE @PositedBy END,
    CASE WHEN (UPDATE([AS_NME_PositedAt])) THEN [i].[AS_NME_PositedAt] ELSE @Now END,
    [i].[AS_NME_PositReliability],
    [i].[AS_GEO_ID],
    [i].[AS_GEO_AS_ID],
    [i].[AS_GEO_Longitude_Deg],
    [i].[AS_GEO_Latitude_Deg],
    CASE WHEN (UPDATE([AS_GEO_ChangedAt])) THEN [i].[AS_GEO_ChangedAt] ELSE @Now END,
    CASE WHEN (UPDATE([AS_GEO_PositedBy])) THEN [i].[AS_GEO_PositedBy] ELSE @PositedBy END,
    CASE WHEN (UPDATE([AS_GEO_PositedAt])) THEN [i].[AS_GEO_PositedAt] ELSE @Now END,
    [i].[AS_GEO_PositReliability],
    ROW_NUMBER() OVER (PARTITION BY [i].[AS_ID] ORDER BY [i].[AS_ID])
    FROM
    [inserted] [i]
    LEFT OUTER JOIN
    [org].[AS_Assets_Current] [c]
    ON [c].[AS_NME_Checksum] = BINARY_CHECKSUM([i].[AS_NME_AssetTag], [i].[AS_NME_AssetName], [i].[AS_NME_AssetDetail])
    LEFT OUTER JOIN
    [org].[AS_Assets_Current] [g]
    ON [g].[AS_GEO_Checksum] = BINARY_CHECKSUM([i].[AS_GEO_Longitude_Deg], [i].[AS_GEO_Latitude_Deg])
    WHERE
    [c].[AS_NME_AS_ID] IS NULL
    OR [g].[AS_NME_AS_ID] IS NULL;
    DECLARE @NME_Posit TABLE
    [AS_NME_ID] INT NOT NULL,
    [AS_NME_Checksum] INT NOT NULL,
    PRIMARY KEY([AS_NME_ID] ASC),
    UNIQUE CLUSTERED([AS_NME_Checksum] ASC)
    INSERT INTO [org].[AS_NME_Assets_Name_Posit]
    [AS_NME_AS_ID],
    [AS_NME_AssetTag],
    [AS_NME_AssetName],
    [AS_NME_AssetDetail],
    [AS_NME_ChangedAt]
    OUTPUT
    [inserted].[AS_NME_ID],
    [inserted].[AS_NME_Checksum]
    INTO
    @NME_Posit
    [AS_NME_ID],
    [AS_NME_Checksum]
    SELECT
    [i].[AS_NME_AS_ID],
    [i].[AS_NME_AssetTag],
    [i].[AS_NME_AssetName],
    [i].[AS_NME_AssetDetail],
    [i].[AS_NME_ChangedAt]
    FROM @Inserted [i];
    INSERT INTO [org].[AS_NME_Assets_Name_Annex]
    [AS_NME_ID],
    [AS_NME_PositedBy],
    [AS_NME_PositedAt],
    [AS_NME_PositReliability]
    SELECT
    [p].[AS_NME_ID],
    CASE WHEN (UPDATE([AS_NME_PositedBy])) THEN [i].[AS_NME_PositedBy] ELSE @PositedBy END,
    CASE WHEN (UPDATE([AS_NME_PositedAt])) THEN [i].[AS_NME_PositedAt] ELSE @Now END,
    [i].[AS_NME_PositReliability]
    FROM @Inserted [i]
    INNER JOIN
    @NME_Posit [p]
    ON [p].[AS_NME_Checksum] = [i].[AS_NME_Checksum];
    INSERT INTO [org].[AS_NME_Assets_Name_Annex]
    [AS_NME_ID],
    [AS_NME_PositedBy],
    [AS_NME_PositedAt],
    [AS_NME_PositReliability]
    SELECT
    [i].[AS_NME_ID],
    CASE WHEN (UPDATE([AS_NME_PositedBy])) THEN [i].[AS_NME_PositedBy] ELSE @PositedBy END,
    CASE WHEN (UPDATE([AS_NME_PositedAt])) THEN [i].[AS_NME_PositedAt] ELSE @Now END,
    [i].[AS_NME_PositReliability]
    FROM [inserted] [i]
    LEFT OUTER JOIN
    @NME_Posit [p]
    ON [p].[AS_NME_Checksum] = BINARY_CHECKSUM([i].[AS_NME_AssetTag])
    WHERE
    [p].[AS_NME_ID] IS NULL;
    DECLARE @GEO_Posit TABLE
    [AS_GEO_ID] INT NOT NULL,
    [AS_GEO_Checksum] INT NOT NULL,
    PRIMARY KEY([AS_GEO_ID] ASC),
    UNIQUE CLUSTERED([AS_GEO_Checksum] ASC)
    INSERT INTO [org].[AS_GEO_Assets_Location_Posit]
    [AS_GEO_AS_ID],
    [AS_GEO_Longitude_Deg],
    [AS_GEO_Latitude_Deg],
    [AS_GEO_ChangedAt]
    OUTPUT
    [inserted].[AS_GEO_ID],
    [inserted].[AS_GEO_Checksum]
    INTO
    @GEO_Posit
    [AS_GEO_ID],
    [AS_GEO_Checksum]
    SELECT
    [i].[AS_GEO_AS_ID],
    [i].[AS_GEO_Longitude_Deg],
    [i].[AS_GEO_Latitude_Deg],
    [i].[AS_GEO_ChangedAt]
    FROM @Inserted [i];
    INSERT INTO [org].[AS_GEO_Assets_Location_Annex]
    [AS_GEO_ID],
    [AS_GEO_PositedBy],
    [AS_GEO_PositedAt],
    [AS_GEO_PositReliability]
    SELECT
    [p].[AS_GEO_ID],
    CASE WHEN (UPDATE([AS_GEO_PositedBy])) THEN [i].[AS_GEO_PositedBy] ELSE @PositedBy END,
    CASE WHEN (UPDATE([AS_GEO_PositedAt])) THEN [i].[AS_GEO_PositedAt] ELSE @Now END,
    [i].[AS_GEO_PositReliability]
    FROM @Inserted [i]
    INNER JOIN
    @GEO_Posit [p]
    ON [p].[AS_GEO_Checksum] = [i].[AS_GEO_Checksum];
    INSERT INTO [org].[AS_GEO_Assets_Location_Annex]
    [AS_GEO_ID],
    [AS_GEO_PositedBy],
    [AS_GEO_PositedAt],
    [AS_GEO_PositReliability]
    SELECT
    [i].[AS_GEO_ID],
    CASE WHEN (UPDATE([AS_GEO_PositedBy])) THEN [i].[AS_GEO_PositedBy] ELSE @PositedBy END,
    CASE WHEN (UPDATE([AS_GEO_PositedAt])) THEN [i].[AS_GEO_PositedAt] ELSE @Now END,
    [i].[AS_GEO_PositReliability]
    FROM [inserted] [i]
    LEFT OUTER JOIN
    @GEO_Posit [p]
    ON [p].[AS_GEO_Checksum] = BINARY_CHECKSUM([i].[AS_GEO_Longitude_Deg], [i].[AS_GEO_Latitude_Deg])
    WHERE
    [p].[AS_GEO_ID] IS NULL;
    END;
    GO
    CREATE TRIGGER [org].[AS_Assets_Current_Delete]
    ON [org].[AS_Assets_Current]
    INSTEAD OF DELETE
    AS
    BEGIN
    SET NOCOUNT ON;
    DECLARE @Now DATETIMEOFFSET(7) = SYSDATETIMEOFFSET();
    DECLARE @PositedBy INT;
    EXECUTE @PositedBy = [posit].[Return_PositorId];
    INSERT INTO [org].[AS_NME_Assets_Name_Annex]
    [AS_NME_ID],
    [AS_NME_PositedBy],
    [AS_NME_PositedAt],
    [AS_NME_PositReliability]
    SELECT
    [d].[AS_NME_ID],
    @PositedBy,
    @Now,
    0
    FROM
    [deleted] [d];
    INSERT INTO [org].[AS_GEO_Assets_Location_Annex]
    [AS_GEO_ID],
    [AS_GEO_PositedBy],
    [AS_GEO_PositedAt],
    [AS_GEO_PositReliability]
    SELECT
    [d].[AS_GEO_ID],
    @PositedBy,
    @Now,
    0
    FROM
    [deleted] [d];
    END;
    GO
    INSERT INTO [org].[AS_Assets_Current]
    [AS].[AS_NME_AssetTag],
    [AS].[AS_NME_AssetName],
    [AS].[AS_NME_AssetDetail],
    [AS].[AS_GEO_Longitude_Deg],
    [AS].[AS_GEO_Latitude_Deg]
    SELECT
    [AS].[AS_NME_AssetTag],
    [AS].[AS_NME_AssetName],
    [AS].[AS_NME_AssetDetail],
    [AS].[AS_GEO_Longitude_Deg],
    [AS].[AS_GEO_Latitude_Deg]
    FROM (VALUES
    ('999', 'Dallas Test 3', 'Dallas Test 3', NULL, NULL, 'Plant', 'AUT', NULL)
    ) [AS]([AS_NME_AssetTag], [AS_NME_AssetName], [AS_NME_AssetDetail], [AS_GEO_Longitude_Deg], [AS_GEO_Latitude_Deg], [CN_ADD_Type_ID], [CN_ADD_Country_ID], [CN_ADD_State]);
    GO

  • Converting each row in a column to an XML

    Hi everyone,
    Using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
    I have a table where there is a comments column which is VARCHAR2. That column contains string data in the form of XML tags.
    Like for eg. *<tag_name attr_name="10"/>* (sorry cant provide the exact values as I'm not allowed to)
    There are many such rows. Now I want to use these strings and operate on them as XML like using XPath to find certain attributes etc.
    I tried using the extract function and to use it i need a XMLType object. So I tried to create one using the XMLType() constructor.
    But it gives me the error ORA-19032: Expected XML tag , got no content
    When I looked it up on the net, I found that this error number doesn't correspond to the error message that I'm getting. The error msg found on the internet was Expected XML tag string got string
    I used this query
    SELECT XMLType (<column>) FROM <table>;But when I modified it (based on someone's hunch) to
    SELECT XMLType (<column>)
      FROM <table>
    WHERE ROWNUM <= 1;The query worked fine. Like it can take only one row.
    I also tried like this
    SELECT XMLType ('<tag_name attr_name="10"/>')
      FROM DUAL;This too worked fine.
    So finally this has left me completely confused. Is there a way to convert every row in a column to an XMLType object so that I can use the extract function to gather information about it.
    For the time being I have used REGEXes to write the code. But having the flexibility of xml would be better.
    Any help would be appreciated.
    Regards,
    Arijit
    Edited by: Arijit Kanrar on May 23, 2013 5:27 AM

    Arijit,
    The error message is correct. What you found is merely the generic message with string placeholders.
    The error message is also pretty self-explanatory : you can't pass an empty string (NULL) to the XMLType constructor.
    SQL> select xmltype('') from dual;
    ERROR:
    ORA-19032: Expected XML tag , got no content
    ORA-06512: at "SYS.XMLTYPE", line 310
    ORA-06512: at line 1
    no rows selectedYou have to either add a WHERE clause to filter out NULL columns, or use a CASE statement to only convert strings that aren't empty :
    SELECT XMLType (<column>)
      FROM <table>
    WHERE <column> IS NOT NULL ;
    SELECT CASE WHEN <column> IS NOT NULL THEN XMLType (<column>) END
    FROM ...And do not use EXTRACT if you want to access scalar values, use EXTRACTVALUE instead :
    SQL> select extractvalue(xmltype('<tag_name attr_name="10"/>'), '/tag_name/@attr_name') from dual;
    EXTRACTVALUE(XMLTYPE('<TAG_NAMEATTR_NAME="10"/>'),'/TAG_NAME/@ATTR_NAME')
    10

  • INSERTING DATA INTO A SQL SERVER 2005 TABLE, WHICH HAS A IDENTITY COLUMN

    Hi All,
    I have to insert the data into a SQL SERVER 2005 Database table.
    I am able to insert the data into a normal SQL Server table.
    When I am trying to insert the data into a SQL Server table, which has a identity column (i.e. auto increment column in Oracle) I am getting error saying that can't insert value explicitly when IDENTITY_INSERT is set to OFF.
    Had anybody tried this??
    There are some SRs on this issue, Oracle agreed that it is a bug. I am wondering if there is any workaround from any one of you (refer Insert in MS-SQL database table with IDENTITY COLUMN
    Thanks
    V Kumar

    Even I had raised a SR on this in October 2008. But didn't get any solution for a long time, finally I had removed the identity column from the table. I can't to that now :).
    I am using 10.1.3.3.0 and MS SQL SERVER 2005, They said it is working for MS SQL SERVER TABLE, if the identity column is not a primary key and asked me to refer to note 744735.1.
    I had followed that note, but still it is not working for me.
    But my requirement is it should work for a MS SQL SERVER 2005 table, which has identity column as primary key.
    Thanks
    V Kumar

  • Select into Temp Table Identity Column

    I'm trying to select data into a temp table but how would I select the identity column into my temp table. This is what I have so far(RefId is the identity Column (1,1)
    BEGIN TRAN
    SELECT [RefId]
    ,[Name]
    ,[CreationDate]
    ,[CreatedBy]
    ,[ModificationDate]
    ,[ModifiedBy]
    ,[RegistrationNumber]
    ,[EmployerType]
    ,[EmployerState]
    ,[ProviderLegalDescription]
    ,[WeeklySalaryDateType]
    ,[WeeklySalaryDateDay]
    ,[FortnightlySalaryDateType]
    ,[FortnightlySalaryDateDay]
    ,[MonthlySalaryDateType]
    ,[MonthlySalaryDateDay]
    ,[TrustLevel]
    ,[ForceDeductionOverrides]
    ,[PayrollPaypointlDeductionsEnabled]
    ,[PaypointRefId]
    ,[PayrollBackupEnabled]
    ,[PayrollBackupFailedPaymentsBefore]
    ,[PayrollBackupType]
    ,[PayrollBackupUploadType]
    ,[PayrollBackupEnableAutomation]
    ,[PayrollBackupAutomationType]
    ,[PayrollBackupFtpServer]
    ,[PayrollBackupFtpPort]
    ,[PayrollBackupFtpPassword]
    ,[PayrollBackupEmail]
    ,[PayrollBackupFtpUsername]
    ,[EnforceSingleProduct]
    ,[AffordabilityOverride]
    ,[AffordabilityReoccuringIncomePercent]
    ,[AffordabilityAdHocIncomePercent]
    ,[AffordabilityVariableIncomePercent]
    ,[AffordabilityNumerator]
    ,[AffordabilityExposure]
    ,[ExternalIdentificationNumber]
    ,[DeductionType]
    ,[IsValidated]
    ,[ValidatedBy]
    ,[ValidatedDate] INTO #TempEmployers FROM Employers WHERE RefId=2
    SELECT
    Name, COUNT(*) AS Repeats INTO #Temp
    FROM
    Employers
    GROUP BY
    Name
    HAVING
    COUNT(*) > 1
    Declare @Nam nvarchar(250)
    While (Select Count(*) From #Temp) > 0
    Begin
    Select Top 1 @Nam = Name From #Temp
    --Do some processing here
    Delete #Temp Where @Nam = Name
    INSERT INTO #TempEmployers
    SELECT [RefId]
    ,[Name]
    ,[CreationDate]
    ,[CreatedBy]
    ,[ModificationDate]
    ,[ModifiedBy]
    ,[RegistrationNumber]
    ,[EmployerType]
    ,[EmployerState]
    ,[ProviderLegalDescription]
    ,[WeeklySalaryDateType]
    ,[WeeklySalaryDateDay]
    ,[FortnightlySalaryDateType]
    ,[FortnightlySalaryDateDay]
    ,[MonthlySalaryDateType]
    ,[MonthlySalaryDateDay]
    ,[TrustLevel]
    ,[ForceDeductionOverrides]
    ,[PayrollPaypointlDeductionsEnabled]
    ,[PaypointRefId]
    ,[PayrollBackupEnabled]
    ,[PayrollBackupFailedPaymentsBefore]
    ,[PayrollBackupType]
    ,[PayrollBackupUploadType]
    ,[PayrollBackupEnableAutomation]
    ,[PayrollBackupAutomationType]
    ,[PayrollBackupFtpServer]
    ,[PayrollBackupFtpPort]
    ,[PayrollBackupFtpPassword]
    ,[PayrollBackupEmail]
    ,[PayrollBackupFtpUsername]
    ,[EnforceSingleProduct]
    ,[AffordabilityOverride]
    ,[AffordabilityReoccuringIncomePercent]
    ,[AffordabilityAdHocIncomePercent]
    ,[AffordabilityVariableIncomePercent]
    ,[AffordabilityNumerator]
    ,[AffordabilityExposure]
    ,[ExternalIdentificationNumber]
    ,[DeductionType]
    ,[IsValidated]
    ,[ValidatedBy]
    ,[ValidatedDate] FROM Employers
    WHERE Name= @Nam
    End
    SELECT * FROM #TempEmployers
    ROLLBACK

    Hi,
    Its the RefId column, I just need the actual values. Im getting the following error:
    Column name or number of supplied values does not match table definition. And it points to The RefId
    Column
    If your question is regarding passing explicit values for identity column you need to set IDENTITY_INSERT to ON and pass a columnlist for the table
    Which column in this is IDENTITY?
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Insert data into a table without identity column

    Hi,
    I need to insert data into a table using data flow task. Unfortunately this table's priamry key column (integer column) is not identity column.  I am looking a way to get the primary key value for the new records. Please advice. Thanks

    Phil has a great post on generating surrogate keys in SSIS: http://www.ssistalk.com/2007/02/20/generating-surrogate-keys/

  • Is there a way to convert 8 Rows by 2 Columns to 2 Rows by 8 Columns?

    I have tried but came to an stop...
    How do I convert 8 Rows by 2 Columns to 2 Rows by 8 Columns?
    as shown in the vi attached
    Thank you very much...
    Solved!
    Go to Solution.
    Attachments:
    Eight Rows Two Col convert to two Rows Eight Col.vi ‏8 KB

    JohnMc19 wrote:
    Hi Diego2000,
    Trying using the Transpose 2D array function found in the Array functions palette, think it is what you are asking for.
    Regards,
    No, for the required transformation reshape array is required, not transpose.
    Compare:
    Andrey.

  • A potential bug on the new feature (12c) of Identity Column?

    Hi,
    I am testing a newly introduced feature of Identity Column in Oracle 12c. I used EclipseLink (JPA) to access the database.
    I may have found a potential bug with this feature. I am getting "ORA-30667: cannot drop NOT NULL constraint on a DEFAULT ON NULL column" when I try to insert a row. My code doesn't explicitly drop "NOT NULL" constraint.
    When I delete all the tables under the user and re-define the user and the tables, the error disappear.
    Here are the details:
    Error:
    DatabaseException Internal Exception: java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1 ORA-30667: cannot drop NOT NULL constraint on a DEFAULT ON NULL column Error Code: 604 Call: INSERT INTO MyTable (ID, SOMEID, SOMEDATE) VALUES (?, ?, ?) bind => [null, 100100147, 2013-11-29 Query: InsertObjectQuery(cus.entity.MyTable@1a9ea5b)
    Table definition:
    CREATE TABLE MyTable (id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
          someId INT NOT NULL,
          someDate DATE NOT NULL,
          PARTITION BY range(someDate)
          interval(numtodsinterval(1,'year'))
          SUBPARTITION BY HASH ( someId)
          SUBPARTITIONS 20
           PARTITION p0 VALUES LESS THAN (TO_DATE('01-12-2013', 'DD-MM-YYYY'))
    Could anyone tell me if there might be a bug associated with the new feature or if there was something wrong with my code?
    I would be appreciated if anyone can help.

    "here is a reproducible test case in the SCOTT schema - if it reproduces for you open an SR with Oracle"
    Yes. I have just followed the instruction you posted and managed to re-produce the same error I reported earlier. Here are the details of the script output following your posted instruction:
    table MYTABLE dropped.
    purge recyclebin
    table MYTABLE created.
    1 rows inserted.
    table MYTABLE dropped.
    OBJECT_NAME                                                                                                                      ORIGINAL_NAME                                                                                                                    OPERATION TYPE                      TS_NAME                        CREATETIME          DROPTIME               DROPSCN PARTITION_NAME                                                                                                                   CAN_UNDROP CAN_PURGE    RELATED BASE_OBJECT PURGE_OBJECT      SPACE
    BIN$6NCDTxmXTb2QBpUWF0kGqw==$0                                                                                                   SYS_C0010655                                                                                                                     DROP      INDEX                     USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030808                                                                                                                                  NO         YES            98789       98789        98812          8
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:30:56 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98790       98789        98789          0
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                                  NO         NO             98833       98789        98789       1024
    BIN$Ka0sgN7XRBeCsjyXTQ76cA==$0                                                                                                   MYTABLE                                                                                                                          DROP      Table Composite Partition USERS                          2013-12-01:10:31:37 2013-12-01:10:32:17    4030812                                                                                                                          &

  • How do you use an entity bea that uses an identity column?

    I am using an mssql database. I need to create an entity bean for a table that uses an identity column. I want to use the identity column as the Primary key in the entity bean.
    I assumed that I should not pass in a paramter for the identity column into the create method of the Home interface or the create method of the Bean ejbCreate method. But when I try using the entitity bean to create a new row in the table I get the following error.
    Cannot insert explicit value for identity column in table 'PropsTableIdentity when IDENTITY_INSERTis set to OFF.
    I didn't think I was doing anything to explicitly insert anything into the identity column.
    Anyways here are my programs if anybody cares to take a look.
    PropsIdentity.java
    package propsIdentity;
    // File generated by Desiderata Software's Blazix entity bean wizard
    // Thu May 05 08:20:44 MDT 2005
    // Remote interface for entity bean "PropsIdentity"
    import javax.ejb.*;
    import java.rmi.*;
    public interface PropsIdentity extends javax.ejb.EJBObject {
         int getKey() throws java.rmi.RemoteException;
         java.lang.String getValue() throws java.rmi.RemoteException;
         void setValue( java.lang.String value ) throws java.rmi.RemoteException;
         // TBD:  Add any additional remote method interfaces
         PropsIdentityHome.java
    package propsIdentity;
    // File generated by Desiderata Software's Blazix entity bean wizard
    // Thu May 05 08:20:44 MDT 2005
    // Home interface for entity bean "PropsIdentity"
    import javax.ejb.*;
    import java.rmi.*;
    import java.util.*;
    public interface PropsIdentityHome extends javax.ejb.EJBHome {
         PropsIdentity create(
                   java.lang.String value
                   ) throws javax.ejb.CreateException, java.rmi.RemoteException;
         PropsIdentity findByPrimaryKey( java.lang.Integer pkey ) throws javax.ejb.FinderException, java.rmi
    .RemoteException;
    }PropsIdentityHome.java
    code]
    package propsIdentity;
    // File generated by Desiderata Software's Blazix entity bean wizard
    // Thu May 05 08:20:44 MDT 2005
    // Home interface for entity bean "PropsIdentity"
    import javax.ejb.*;
    import java.rmi.*;
    import java.util.*;
    public interface PropsIdentityHome extends javax.ejb.EJBHome {
         PropsIdentity create(
                   java.lang.String value
                   ) throws javax.ejb.CreateException, java.rmi.RemoteException;
         PropsIdentity findByPrimaryKey( java.lang.Integer pkey ) throws javax.ejb.FinderException, java.rmi
    .RemoteException;
    PropsIdentityBean.java
    package propsIdentity;
    // File generated by Desiderata Software's Blazix entity bean wizard
    // Thu May 05 08:20:44 MDT 2005
    // Home interface for entity bean "PropsIdentity"
    import javax.ejb.*;
    import java.rmi.*;
    import java.util.*;
    public interface PropsIdentityHome extends javax.ejb.EJBHome {
         PropsIdentity create(
                   java.lang.String value
                   ) throws javax.ejb.CreateException, java.rmi.RemoteException;
         PropsIdentity findByPrimaryKey( java.lang.Integer pkey ) throws javax.ejb.FinderException, java.rmi
    .RemoteException;
    }PropsIdentityBean.java
    // Thu May 05 08:20:44 MDT 2005
    // Bean class for entity bean "PropsIdentity"
    import javax.ejb.*;
    import javax.naming.*;
    import java.rmi.*;
    public class PropsIdentityBean implements javax.ejb.EntityBean {
         //Instance member variables.
         public int key = 0;
         public java.lang.String value = null;
         // Entity context, can be used to obtain handles etc
         javax.ejb.EntityContext ejbEntityContext = null;
         //Getter/setter methods
         public int getKey() throws java.rmi.RemoteException
              return key;
         public java.lang.String getValue() throws java.rmi.RemoteException
              return value;
         public void setValue( java.lang.String value ) throws java.rmi.RemoteException
              this.value = value;
         // TBD:  Add implementations for any additional remote method interfaces
         // The default ejbCreate method.
         public java.lang.Integer ejbCreate(
                   java.lang.String value
              throws javax.ejb.CreateException, java.rmi.RemoteException
              this.value = value;
              return null;
         // TBD:  If any other ejbCreate's are added manually to the home interface, define them.
         // Other methods required in an entity bean
         public void setEntityContext( javax.ejb.EntityContext ejbEntityContext )
              throws RemoteException
              this.ejbEntityContext = ejbEntityContext;
         public void unsetEntityContext()
              throws RemoteException
              this.ejbEntityContext = null;
         public void ejbPostCreate(
                   java.lang.String value
         // TBD:  Do any post-instance-creation processing here
         public void ejbRemove()
              throws java.rmi.RemoteException, javax.ejb.RemoveException
         // TBD:  Do any processing here when instance is being removed
         public void ejbActivate()
              throws java.rmi.RemoteException
         // TBD:  Do any processing here when instance is activated
         public void ejbPassivate()
              throws java.rmi.RemoteException
         // TBD:  Do any processing here when instance is being passivated
         public void ejbLoad()
              throws java.rmi.RemoteException
         // TBD:  Load any data needed by instance
         //       in addition to the container-managed data.
         public void ejbStore()
              throws java.rmi.RemoteException
         // TBD:  Store any data used by instance
         //       in addition to the container-managed data.
    }     Script used to create table in mssql
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PropsTableIdentity]') and OBJE
    CTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[PropsTableIdentity]
    GO
    CREATE TABLE [dbo].[PropsTableIdentity] (
         [key] [int] IDENTITY (1, 1) NOT NULL ,
         [value] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
    ) ON [PRIMARY]
    GOAnybody have any clue on how to figure the entity bean to work with the identity column?

    Hi,
    CAN THIS BE DONE? This would be a good enhancement if not...???
    If I write a PL/SQL loop and want to add it to the utilities... IS THERE A WAY?

  • Equivalent to SQL Server IDENTITY columns in Oracle 8i?

    Under SQL Server, my app frequently keys tables using IDENTITY columns which are also used as the only column in the tables primary key. After an INSERT, I typically retrieve the value assigned to the IDENTITY column using:
    SELECT @@IDENTITY
    I need to port my app to Oracle 8i and wonder if there is a similar concept available. I checked out ROWID and UROWID but they don't sound quite right.
    Any idea?

    You can use the sequence directly in your insert
    without use a trigger
    For example:
    SQL> Create table nn ( c1 number, c2 varchar2(34));
    Table created.
    SQL>
    SQL> CREATE SEQUENCE customers_seq
    2 START WITH 5
    3 INCREMENT BY 1
    4 NOCACHE
    5 NOCYCLE;
    Sequence created.
    SQL>
    SQL> insert into nn values (customers_seq.nextval, 'jjj');
    1 row created.
    SQL> insert into nn values (customers_seq.nextval, 'mmm');
    1 row created.
    SQL> select * from nn;
    C1 C2
    5 jjj
    6 mmm
    SQL>
    [email protected]
    Joel P�rez

  • Database Adapter: How to Insert when one column is an identity column

    Hi everyone
    I'm developing a BPEL process who uses a database adapter to insert a row in a table of an SQL Server database. The problem is that the database adapter tries to insert a null value into the field that is the primary key of the table so the process fails. This is because I don't want to specify any value to this field because this field is specified in sql server as an identity column so this field doesn't need to have a value provided.
    I suppose the only solution is to set the database adapter to not insert any value to this field but how can i do that? is there any way to make the database adapter to insert data in only a few fields of a table and not in all fields, trying to insert null in these fields that no data have been provided?
    Thank You Very Much!

    In JDev->Applications Navigator->your project->Application Sources->Toplink->toplink_mappings.
    Upon selecting "toplink_mappings" in the structure window you will see the package. Expand to see your tables. Double click your table and it will open file in main area. Select your field that has identity column. And at the botton you will see "Use Sequencing" check box make sure you uncheck it.
    This will solve your problem.
    Dipal

  • SQL 7 - Oracle 8i - NOT NULL dropped for IDENTITY column

    It appears that OMWB is dropping the NOT NULL condition for columns defined as IDENTITY in SQL server 7.
    SQL code to create table:
    CREATE TABLE [dbo].[PCPrsnCorp] (
    [PrsnCorpId] [int] IDENTITY (1, 1) NOT NULL ,
    [PrsnCorpTpEnum] [tinyint] NOT NULL ,
    [Name] [varchar] (128) NOT NULL ,
    [NameFirstIdx] [smallint] NULL ,
    [NameMidIdx] [smallint] NULL ,
    [NameLastIdx] [smallint] NULL ,
    [NameSuffixIdx] [smallint] NULL ,
    [NameLine2Idx] [smallint] NULL ,
    [CmpyId] [smallint] NULL ,
    [ClsnId] [int] NOT NULL
    ) ON [PRIMARY]
    GO
    OMWB migration script:
    REM
    REM Message : Created Table :sa.PCPRSNCORP
    REM User : system
    CREATE TABLE sa.PCPRSNCORP(PRSNCORPID NUMBER (10,0) ,PRSNCORPTPENUM NUMBER
    (3,0) NOT NULL,NAME VARCHAR2 (128) NOT NULL,NAMEFIRSTIDX NUMBER (5,0)
    ,NAMEMIDIDX NUMBER (5,0) ,NAMELASTIDX NUMBER (5,0) ,NAMESUFFIXIDX NUMBER
    (5,0) ,NAMELINE2IDX NUMBER (5,0) ,CMPYID NUMBER (5,0) ,CLSNID NUMBER
    (10,0) NOT NULL) TABLESPACE ORACLEFULL
    NOT NULL appears to be handled correctly if colummn is not defined as IDENTITY. Is there a patch, workaround, or OMWB option to get past this?

    Currently, the Migration Workbench converts IDENTITY columns into a BEFORE INSERT trigger and an Oracle sequence.
    This trigger will fire prior to any INSERT statement executing against the table. The trigger inserts the next value of the defined sequence into the converted IDENTITY column.
    The NOT NULL column attribute is therefore no longer needed.
    Strictly speaking, it would do no harm to keep the NOT NULL column attribute and so I will log a bug on your behalf.
    Thanks for the info.
    Brian.

Maybe you are looking for

  • My address bar has disappeared in Safari 5.1 - not the same issue as discussed elsewhere in Forum

    My address bar has disappeared in Safari 5.1. When I click "Customize Toolbar"  to fix it, the Home and arrow buttons become unusable--they just click but nothing happens.See image below. I have to close the window and open a new one to get the butto

  • I created an album in Photos how do I get iPhoto to sync

    Could someone tell me how to get the album over to iPhoto? iPhoto is just saying I can import these photos but I've already grouped them on my iPad - would rather not do it again on Mac...

  • LINE IN!!! HELP ME PLEAS

    Ok I am going tired of this support forum. The only thing I want to know is how do I get the line in on my Audigy SE to play over 5. surround sound instead of the 2. that it is playing over now. I was able to get this to play over 5. before I had to

  • DP Forecastion - Desegregation?

    Hi.. I have a scenario in DP Forecasting : No of plants :2 -     I load history for Plant A only & run forecast. The forecast output I get is for both Plant A & Plant B Eg: Plant A u2013 History                       Product 1 :50     50     50      

  • NullPointerException trying to ViewObject.setCurrentRow(Row)

    JDev 10.1.2 build 1811 ... JClient app Basically, I'm attempting to save and restore a view's currency before and after clearing the entity cache of one of its entities. The code is executed in the event thread (later) in beforeSetAttribute if that m