IDENTITY_INSERT ON

Why doesn't this work?
SET IDENTITY_INSERT TemoCatalogProducts ON
INSERT INTO TempCatalogProducts
SELECT * FROM CatalogProducts WHERE VariantID IN ('125244', '104907', '144083', '144098', '144099', '144097', '144096')
I still get the error:
Msg 8101, Level 16, State 1, Line 2
An explicit value for the identity column in table 'TempCatalogProducts' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Kevin Burton

You need to write your insert this way:
INSERT INTO TempCatalogProducts
(ProductId, Column1, Column2)
SELECT ProductId, Column1, Column2 FROM CatalogProducts WHERE VariantID IN ('125244', '104907', '144083', '144098', '144099', '144097', '144096')
In other words, you need to specify all columns in both INSERT INTO and then in the SELECT.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog

Similar Messages

  • IDENTITY_INSERT is set to OFF.

    I have a dynamic site.
    When I insert an integer (a whole number) in a raw materials purchase table, I get the following message:
    Error Executing Database Query.
    [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert explicit value for identity column in table 'tblRawMatlPurch' when IDENTITY_INSERT is set to OFF.           
    When I change to or insert a numeric, decimal, or money value, I get the following message:
    Raw Materials Decision
    Company:  Grande
    You have NOT successfully submitted the Raw Materials Decision form
    Please note that the purchase amount must be a whole number, please do not enter a decimal for this number.
    Return to correct
    I have two programs: one is in the secure section, and the name is secure/raw_materials_decision_action, indicating that the raw material purchase variable (rawMat) is a money variable. Giving this information I set it in SQL as a money variable. Here is the file:
    <!---  get Company Name --->
    <cfquery name="getCompany" datasource="#application.dsn#">
      Select companyName
      From tblCompNames
      Where companyID=<cfqueryparam cfsqltype="cf_sql_integer" value="#getAuthUser()#">
    </cfquery>
    <cfparam name="form.changes" default="">
    <cfset error = "">
    <!--- All users must have raw materials associated with city and product when user profile created --->
    <!--- update action --->
    <cfif form.changes NEQ "">
    <!---  go through changes - if they changed cost or selling price, will contain cost_id --->
      <cfloop index="x" list="#form.changes#">
      <cfif trim(x) NEQ "">
      <cfset thisSalesOrderID = trim(x)>
      <cfset thisRawMatID = form["rawMatID_#thisSalesOrderID#"]>
      <cfset thisCity = form["cityID_#thisSalesOrderID#"]>
      <cfset thisProduct = form["productID_#thisSalesOrderID#"]>
      <cfset thisPurchase = form["purchase_#thisSalesOrderID#"]>
      <cfif thisPurchase NEQ "" AND (not isNumeric(thisPurchase) OR thisPurchase CONTAINS ".")>
      <cfset error = "yes">
      </cfif>
      <cfif error EQ "">
      <cfquery name="getRow" datasource="#application.dsn#">
      Select *
      From tblRawMatlPurch
      WHERE SalesOrderID=<cfqueryparam cfsqltype="cf_sql_integer" value="#thisSalesOrderID#">
      </cfquery>
      <cfif getRow.RawMat NEQ thisPurchase>
      <cfif getRow.recordCount NEQ 0 AND trim(thisPurchase) NEQ "">
      <cfquery name="updateRow" datasource="#application.dsn#">
      Update tblRawMatlPurch
      Set CityID = <cfqueryparam cfsqltype="cf_sql_integer" value="#thisCity#">
      , ProductID = <cfqueryparam cfsqltype="cf_sql_integer" value="#thisProduct#">
      , RawMatID = <cfqueryparam cfsqltype="cf_sql_integer" value="#thisRawMatID#">
      , RawMat = <cfqueryparam cfsqltype="cf_sql_money" value="#trim(thisPurchase)#">
      WHERE SalesOrderID=<cfqueryparam cfsqltype="cf_sql_integer" value="#thisSalesOrderID#">
      </cfquery>
      <cfelseif getRow.recordCount NEQ 0 AND trim(thisPurchase) EQ "">
      <cfquery name="deleteRow" datasource="#application.dsn#">
      Delete From tblRawMatlPurch
      WHERE SalesOrderID=<cfqueryparam cfsqltype="cf_sql_integer" value="#thisSalesOrderID#">
      </cfquery>
      <cfelseif getRow.recordCount EQ 0 AND thisPurchase NEQ "">
      <cfquery name="insertRow" datasource="#application.dsn#">
      Insert Into tblRawMatlPurch
      (SalesOrderID,companyID,cityID, productID,RawMatID,RawMat)
      VALUES
      (<cfqueryparam cfsqltype="cf_sql_integer" value="#thisSalesOrderID#">,<cfqueryparam cfsqltype="cf_sql_integer" value="#getAuthUser()#">, <cfqueryparam cfsqltype="cf_sql_integer" value="#thisCity#">, <cfqueryparam cfsqltype="cf_sql_integer" value="#thisProduct#">,<cfqueryparam cfsqltype="cf_sql_integer" value="#thisRawMatID#">,<cfqueryparam cfsqltype="cf_sql_money" value="#trim(thisPurchase)#">)
      </cfquery>
      </cfif>
      </cfif>
      </cfif>
      </cfif>
      </cfloop>
    </cfif>
    However, I have a second program in the files section: the raw material decision, which indicates that the variable must be an integer (a whole number).
    <!---  Text Content for Raw Materials Decision Form
      DO NOT CHANGE ANY FORM NAMES OR ADD NEW FORM NAMES
      <input type="text" name="DO NOT CHANGE". . .>
      See raw_materials_decison_es.html for Spanish version of this file --->
    <!---  User can enter just one purchase
      - the next time they use this screen it will show blank city/product/raw material purchases
      error message if they do not enter numeric value --->
    <!---  get Materials for this company --->
    <cfquery name="getMaterials" datasource="#application.dsn#">
      SELECT SalesOrderID, CityID, ProductID, RawMatID
      FROM tblRawMatID
      WHERE CompanyID=<cfqueryparam cfsqltype="cf_sql_integer" value="#getAuthUser()#">
      ORDER BY cityID, productID, rawMatID
    </cfquery>
    <!--- set Company name --->
    <cfset thisCompany = getCompany.companyName>
    <table width="600" border="0" cellpadding="5" align="center">
      <cfoutput>
      <tr>
      <td colspan="5" align="right">
      <a href="logout.cfm" style="text-decoration:none; font-weight:bold;">LOGOUT</a>
      </td>
      </tr>
      <tr>
      <td colspan="5">
      <h2>Raw Materials Decision</h2>
      <h5>Company:  #thiscompany#</h5>
      </td>
      </tr>
      </cfoutput>
    <!---  Action display --->
    <cfif form.changes NEQ "">
      <!--- Error Message - if there --->
      <cfif error NEQ "">
      <tr>
      <td colspan="5">
      <p>
      You have NOT successfully submitted the Raw Materials Decision form
      </p>
      <p>
      Please note that the purchase amount must be a whole number, please do not enter a decimal for this number.
      <br /><br />
      <a href='Javascript: history.back();'>Return to correct</a>
      </p>
      </td>
      </tr>
      <cfelse>
      <tr>
      <td colspan="5">
      <p>
      Thank you for your submission.
      </p>
      </td>
      </tr>
      </cfif>
    <!---  START FORM --->
    <cfelse>
      <!---  Show Materials already entered when Company set up --->
      <form action="raw_materials_decision.cfm" method="post" name="materials">
      <!---  changes hold the ID for any values that are changed to minimize time to check for changes
      - uses onChange in form input to send ID --->
      <input type="hidden" name="changes" value="" />
      <!--- top column headings for table --->
      <tr>
      <th>
      City
      </th>
      <th>
      Product
      </th>
      <th>Raw Materials</th>
      <th>
      Price</th>
      <th align="center">
      Purchase
      </th>
      </tr>
      <cfoutput query="getMaterials">
      <cfquery name="getCity" datasource="#application.dsn#">
      Select cityName
      From tblCities
      Where cityID = <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.cityID#">
      </cfquery>
      <cfquery name="getProduct" datasource="#application.dsn#">
      Select productName
      From tblProductCategories
      Where productID = <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.productID#">
      </cfquery>
      <cfquery name="getMaterial" datasource="#application.dsn#">
      Select rawMatDescription
      From tblRmatCategory
      Where rawMatID = <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.rawMatID#">
      </cfquery>
      <cfquery name="getPrice" datasource="#application.dsn#">
      Select rawMatPrice
      From tblRawmatPrices
      Where rawMatID = <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.rawMatID#">
      AND cityID= <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.cityID#">
      </cfquery>
      <cfquery name="getPurch" datasource="#application.dsn#">
      SELECT RawMat
      FROM tblRawMatlPurch
      WHERE companyID=<cfqueryparam cfsqltype="cf_sql_integer" value="#getAuthUser()#">
      AND cityID = <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.cityID#">
      AND productID = <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.productID#">
      AND rawMatID =  <cfqueryparam cfsqltype="cf_sql_integer" value="#getMaterials.RawMatID#">
      </cfquery>
      <tr>
      <td>
      #getCity.cityName#
      <input type="hidden" name="cityID_#salesOrderID#" value="#cityID#" />
      </td>
      <td>
      #getProduct.productName#
      <input type="hidden" name="productID_#salesOrderID#" value="#productID#" />
      </td>
      <td>
      #getMaterial.RawMatDescription#
      <input type="hidden" name="rawMatID_#salesOrderID#" value="#RawMatID#">
      </td>
      <td>
      #dollarFormat(getPrice.rawMatPrice)#
      </td>
      <td align="center">
      <input  name="purchase_#salesOrderID#" type="text" value="#getPurch.rawMat#" size="12" onchange="document.materials.changes.value=document.materials.changes.value + ', #salesOrderID#';" />
      </td>
      </tr>
      </cfoutput>
      <!--- blank space before submit button --->
      <tr>
      <td colspan="5">
      <br />
      </td>
      </tr>
      <!--- submit buttons --->
      <tr>
      <td colspan="5">
      <input type="submit" value="Submit Raw Materials" />
      <input type="reset" value="Reset">
      </td>
      </tr>
      </form>
    </cfif>
    </table>
    I understand there is a conflict between the secure/raw_materials_decision_action program and the raw materials decision program, except, that I do not know how to fix it.
    Perhaps, I could change, the raw materials variable from money to integer. But, I am not sure this will solve the problem.
    Alternatively, I could try to change the raw_materials_decision, specification, to accept a decimal, numeric, or money variable, but, I have been revieweing the file, and I do not know how to make this change.
    It is not obvious to me.
    Is there anyone who could help with this problem to find a best possible solution?
    I would appreciate the assistance very much.
    Thank you.

    TL;DR. The error you are receiving is from SQL. Identity fields are auto-assigned by the SQL server and you are sending a prepopulated value, thus the error. I can't really tell you how to easily fix this because I'm not sure what the app is trying to do nor do I know the underlying database schema. The most likely solution is to not send the identity value in your insert query and then use select @@identity if you require the auto-assigned value.

  • IDENTITY_INSERT Error

    We have recently migrated to Coldfusion 8 and have found that certain ALTER SQL commands that ran just fine in our old Coldfusion 7 environment will generate errors in CF8. We verified that all permission are given in both Coldfusion 8 Administrator Datasource Settings and SQLServer 2005 for ALTER rights to this table but we continue to get the following error.
    [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot find the object "dbo.SCI_Group" because it does not exist or you do not have permissions.
    Here is our SQL Query that we are executing:
          DECLARE @base INT
          DECLARE @fyr INT
          SET @base = IDENT_CURRENT('dbo.SCI_Group')
          SET @fyr = 2009
          SET IDENTITY_INSERT dbo.SCI_Group ON
          INSERT INTO SCI_Group
            (ID, ParID, OldID, DowID, FYR, Name, Sort, Description, f_Input, f_Output, f_Enabled, f_Parent)
            SELECT
            ID + @base,
            ParID + @base,
            ID,
            DowID,
            @fyr,
            Name,
            Sort,
            Description,
            f_Input,
            f_Output,
            f_Enabled,
            f_Parent
          FROM
            SCI_Group
          WHERE
            FYR = (@fyr - 1)
          SET IDENTITY_INSERT dbo.SCI_Group OFF
    Any insight from prior experience on this error type is much appreciated.
    Thanks!
    Mike

    Things to check:
    1. Does the code execute correctly without SET IDENTITY_INSERT statements?
    2. Check permissions for your login.  From the Microsoft documentation for SET IDENTITY_INSERT: "User must own the object, or be a member of the sysadmin fixed server role, or the db_owner and db_ddladmin fixed database roles."
    http://msdn.microsoft.com/en-us/library/ms188059(SQL.90).aspx
    From the Microsoft documentation for IDENT_CURRENT: "Returns NULL on error or if a caller does not have permission to view the object. In SQL Server 2005, a user can only view the metadata of securables that the user owns or on which the user has been granted permission. This means that metadata-emitting, built-in functions such as IDENT_CURRENT may return NULL if the user does not have any permission on the object. For more information, see Metadata Visibility Configuration and Troubleshooting Metadata Visibility."
    http://msdn.microsoft.com/en-us/library/ms175098(SQL.90).aspx
    3. Can you wrap your SQL into a stored procedure and using that instead of using a batch of SQL statements?
    Were there any database, network, or ColdFusion changes in the upgrade other then the move from CF7 to CF8?

  • Detect Current IDENTITY_INSERT Settings?

    Is there any way to programmatically detect the current value(s) of the IDENTITY_INSERT property, specifically (a) whether it's ON or OFF, and/or (b) if it's ON which table it's on for?
    I have a table with an INSTEAD OF INSERT trigger which does a data check prior to insertion.  The table has existing data.  I'm trying to add the IDENTITY property to one of the columns in the PK so that going forward, the PK value is automatically generated on new rows.  Unfortunately, the INSERT in the trigger only works if IDENTITY_INSERT is off.  If IDENTITY_INSERT myTable is ON, the INSERT statement in the trigger fails because the identiy column is not coded in it.
    I tried putting the INSERT in a TRY...CATCH block, testing for error 545 in the CATCH and issuing a second INSERT with the PK column coded in it, but once you hit the CATCH block in a trigger SQL Server deems the entire transaction as "failed", and you can only roll it back (error 3930).
    CREATE TRIGGER myTable_tIiof
    ON myTable INSTEAD OF INSERT
    AS
    BEGIN
     SET NOCOUNT ON;
     IF (EXISTS (SELECT TOP 1 i1.col2 FROM inserted i1
      WHERE (EXISTS (SELECT TOP 1 r1.col1
        FROM myTable r1
        WHERE i1.col2= r1.col2
        AND UPPER(i1.col3) = UPPER(r1.col3)) ))) BEGIN
        PRINT 'INSERT failed - violation of duplicate col2 and col3 restriction';
     END ELSE
     BEGIN TRY
       INSERT INTO myTable (col2, col3, col4)
       SELECT i.col2, i.col3, i.col4 FROM inserted i
     END TRY
     BEGIN CATCH
       IF ERROR_NUMBER() = 545 BEGIN    -- IDENTITY_INSERT is on:
         BEGIN TRY
          INSERT INTO myTable (col1, col2, col3, col4)
          SELECT i.col1, i.col2, i.col3, i.col4 FROM inserted i
         END TRY
         BEGIN CATCH  -- Some other error occurred after second INSERT attempt:
          SELECT ERROR_NUMBER() AS ErrorNumber;
          IF @@TRANCOUNT > 0 ROLLBACK;
         END CATCH
       END ELSE BEGIN --
         SELECT ERROR_NUMBER() AS ErrorNumber;
         IF @@TRANCOUNT > 0 ROLLBACK;
       END
     END CATCH
    END
    IDEALLY, I want to do the following:
    CREATE TRIGGER myTable_tIiof
    ON myTable INSTEAD OF INSERT
    AS
    BEGIN
     SET NOCOUNT ON;
     IF (EXISTS (SELECT TOP 1 i1.col2 FROM inserted i1
      WHERE (EXISTS (SELECT TOP 1 r1.col1
        FROM myTable r1
        WHERE i1.col2= r1.col2
        AND UPPER(i1.col3) = UPPER(r1.col3)) ))) BEGIN
        PRINT 'INSERT failed - violation of duplicate col2 and col3 restriction';
     END ELSE BEGIN
       IF MissingFunction1(IsIdentityInsertOn) = true AND MissingFunction2(IdentityInsertObject) = 'myTable' BEGIN
          INSERT INTO myTable (col1, col2, col3, col4)
          SELECT i.col1, i.col2, i.col3, i.col4 FROM inserted i
       END ELSE BEGIN
         INSERT INTO myTable (col2, col3, col4)
         SELECT i.col2, i.col3, i.col4 FROM inserted i
       END
    END
    Do MissingFunction1 and/or MissingFunction2 exist?  If so, what are they called?
    (And if they don't exist, why don't they exist?)
    Thanks in advance... Bryan

    I figured out a solution to this problem in the case where you are trying to re-insert an old record into a table (insert an ID that is lower than would be inserted normally).  I put the following code around the part of the trigger that won't work
    with IDENTITY_INSERT set on (in my case a part of the trigger that inserts related records into the same table)
    if
    (select
    max(id)
    from
    MyTable) <
    (select
    max(id)
    from inserted)
    --Then you may be inserting a record normally
    BEGIN
        set @I
    = 1
    --SQL wants something to happen in the "IF" side of an IF/ELSE
    END
    ELSE --You definitely have IDENTITY_INSERT on.  Done as ELSE instead of the other way around so that if there is no inserted table, it will run anyway
    BEGIN
    .... Code that shouldn't run with IDENTITY_INSERT on
    END

  • How to write a cursor to check every row of a table which has millions of rows

    Hello every one.
    I need help. please... Below is the script (sample data), You can run directly on sql server management studio.
    Here we need to update PPTA_Status column in Donation table. There WILL BE 3 statuses, A1, A2 and Q.
    Here we need to update PPTA_status of January month donations only. We need to write a cursor. Here as this is a sample data we have only some donations (rows), but in the real table we have millions of rows. Need to check every row.
    If i run the cursor for January, cursor should take every row, row by row all the rows of January.
    we have donations in don_sample table, i need to check the test_results in the result_sample table for that donations and needs to update PPTA_status COLUMN.
    We need to check all the donations of January month one by one. For every donation, we need to check for the 2 previous donations. For the previous donations, we need to in the following way. check
    If we want to find previous donations of a donation, first look for the donor of that donation, then we can find previous donations of that donor. Like this we need to check for 2 previous donations.
    If there are 2 previous donations and if they have test results, we need to update PPTA_STATUS column of this donatioh as 'Q'.
    If 2 previous donation_numbers  has  test_code column in result_sample table as (9,10,11) values, then it means those donations has result.
    BWX72 donor in the sample data I gave is example of above scenario
    For the donation we are checking, if it has only 1 previous donation and it has a result in result_sample table, then set this donation Status as A2, after checking the result of this donation also.
    ZBW24 donor in the sample data I gave is example of above scenario
    For the donation we are checking, if it has only 1 previous donation and it DO NOT have a result in result_sample table, then set this donation Status as A1. after checking the result of this donation also.
    PGH56 donor in the sample data I gave is example of above scenario
    like this we need to check all the donations in don_sample table, it has millions of rows per every month.
    we need to join don_sample and result_sample by donation_number. And we need to check for test_code column for result.
    -- creating table
    CREATE TABLE [dbo].[DON_SAMPLE](
    [donation_number] [varchar](15) NOT NULL,
    [donation_date] [datetime] NULL,
    [donor_number] [varchar](12) NULL,
    [ppta_status] [varchar](5) NULL,
    [first_time_donation] [bit] NULL,
    [days_since_last_donation] [int] NULL
    ) ON [PRIMARY]
    --inserting values
    Insert into [dbo].[DON_SAMPLE] ([donation_number],[donation_date],[donor_number],[ppta_status],[first_time_donation],[days_since_last_donation])
    Select '27567167','2013-12-11 00:00:00.000','BWX72','A',1,0
    Union ALL
    Select '36543897','2014-12-26 00:00:00.000','BWX72','A',0,32
    Union ALL
    Select '47536542','2014-01-07 00:00:00.000','BWX72','A',0,120
    Union ALL
    Select '54312654','2014-12-09 00:00:00.000','JPZ41','A',1,0
    Union ALL
    Select '73276321','2014-12-17 00:00:00.000','JPZ41','A',0,64
    Union ALL
    Select '83642176','2014-01-15 00:00:00.000','JPZ41','A',0,45
    Union ALL
    Select '94527541','2014-12-11 00:00:00.000','ZBW24','A',0,120
    Union ALL
    Select '63497874','2014-01-13 00:00:00.000','ZBW24','A',1,0
    Union ALL
    Select '95786348','2014-12-17 00:00:00.000','PGH56','A',1,0
    Union ALL
    Select '87234156','2014-01-27 00:00:00.000','PGH56','A',1,0
    --- creating table
    CREATE TABLE [dbo].[RESULT_SAMPLE](
    [test_result_id] [int] IDENTITY(1,1) NOT NULL,
    [donation_number] [varchar](15) NOT NULL,
    [donation_date] [datetime] NULL,
    [test_code] [varchar](5) NULL,
    [test_result_date] [datetime] NULL,
    [test_result] [varchar](50) NULL,
    [donor_number] [varchar](12) NULL
    ) ON [PRIMARY]
    ---SET IDENTITY_INSERT dbo.[RESULT_SAMPLE] ON
    ---- inserting values
    Insert into [dbo].RESULT_SAMPLE( [test_result_id], [donation_number], [donation_date], [test_code], [test_result_date], [test_result], [donor_number])
    Select 278453,'27567167','2013-12-11 00:00:00.000','0009','2014-01-20 00:00:00.000','N','BWX72'
    Union ALL
    Select 278454,'27567167','2013-12-11 00:00:00.000','0010','2014-01-20 00:00:00.000','NEG','BWX72'
    Union ALL
    Select 278455,'27567167','2013-12-11 00:00:00.000','0011','2014-01-20 00:00:00.000','N','BWX72'
    Union ALL
    Select 387653,'36543897','2014-12-26 00:00:00.000','0009','2014-01-24 00:00:00.000','N','BWX72'
    Union ALL
    Select 387654,'36543897','2014-12-26 00:00:00.000','0081','2014-01-24 00:00:00.000','NEG','BWX72'
    Union ALL
    Select 387655,'36543897','2014-12-26 00:00:00.000','0082','2014-01-24 00:00:00.000','N','BWX72'
    UNION ALL
    Select 378245,'73276321','2014-12-17 00:00:00.000','0009','2014-01-30 00:00:00.000','N','JPZ41'
    Union ALL
    Select 378246,'73276321','2014-12-17 00:00:00.000','0010','2014-01-30 00:00:00.000','NEG','JPZ41'
    Union ALL
    Select 378247,'73276321','2014-12-17 00:00:00.000','0011','2014-01-30 00:00:00.000','NEG','JPZ41'
    UNION ALL
    Select 561234,'83642176','2014-01-15 00:00:00.000','0081','2014-01-19 00:00:00.000','N','JPZ41'
    Union ALL
    Select 561235,'83642176','2014-01-15 00:00:00.000','0082','2014-01-19 00:00:00.000','NEG','JPZ41'
    Union ALL
    Select 561236,'83642176','2014-01-15 00:00:00.000','0083','2014-01-19 00:00:00.000','NEG','JPZ41'
    Union ALL
    Select 457834,'94527541','2014-12-11 00:00:00.000','0009','2014-01-30 00:00:00.000','N','ZBW24'
    Union ALL
    Select 457835,'94527541','2014-12-11 00:00:00.000','0010','2014-01-30 00:00:00.000','NEG','ZBW24'
    Union ALL
    Select 457836,'94527541','2014-12-11 00:00:00.000','0011','2014-01-30 00:00:00.000','NEG','ZBW24'
    Union ALL
    Select 587345,'63497874','2014-01-13 00:00:00.000','0009','2014-01-29 00:00:00.000','N','ZBW24'
    Union ALL
    Select 587346,'63497874','2014-01-13 00:00:00.000','0010','2014-01-29 00:00:00.000','NEG','ZBW24'
    Union ALL
    Select 587347,'63497874','2014-01-13 00:00:00.000','0011','2014-01-29 00:00:00.000','NEG','ZBW24'
    Union ALL
    Select 524876,'87234156','2014-01-27 00:00:00.000','0081','2014-02-03 00:00:00.000','N','PGH56'
    Union ALL
    Select 524877,'87234156','2014-01-27 00:00:00.000','0082','2014-02-03 00:00:00.000','N','PGH56'
    Union ALL
    Select 524878,'87234156','2014-01-27 00:00:00.000','0083','2014-02-03 00:00:00.000','N','PGH56'
    select * from DON_SAMPLE
    order by donor_number
    select * from RESULT_SAMPLE
    order by donor_number

    You didn't mention the version of SQL Server.  It's important, because SQL Server 2012 makes the job much easier (and will also run much faster, by dodging a self join).  (As Kalman said, the OVER clause contributes to this answer).  
    Both approaches below avoid needing the cursor at all.  (There was part of your explanation I didn't understand fully, but I think these suggestions work regardless)
    Here's a SQL 2012 answer, using LAG() to lookup the previous 1 and 2 donation codes by Donor:  (EDIT: I overlooked a couple things in this post: please refer to my follow-up post for the final/fixed answer.  I'm leaving this post with my overlooked
    items, for posterity).
    With Results_Interim as
    Select *
    , count('x') over(partition by donor_number) as Ct_Donations
    , Lag(test_code, 1) over(partition by donor_number order by donation_date ) as PrevDon1
    , Lag(test_code, 2) over(partition by donor_number order by donation_date ) as PrevDon2
    from RESULT_SAMPLE
    Select *
    , case when PrevDon1 in (9, 10, 11) and PrevDon2 in (9, 10, 11) then 'Q'
    when PrevDon1 in (9, 10, 11) then 'A2'
    when PrevDon1 is not null then 'A1'
    End as NEWSTATUS
    from Results_Interim
    Where Test_result_Date >= '2014-01' and Test_result_Date < '2014-02'
    Order by Donor_Number, donation_date
    And a SQL 2005 or greater version, not using SQL 2012 new features
    With Results_Temp as
    Select *
    , count('x') over(partition by donor_number) as Ct_Donations
    , Row_Number() over(partition by donor_number order by donation_date ) as RN_Donor
    from RESULT_SAMPLE
    , Results_Interim as
    Select R1.*, P1.test_code as PrevDon1, P2.Test_Code as PrevDon2
    From Results_Temp R1
    left join Results_Temp P1 on P1.Donor_Number = R1.Donor_Number and P1.Rn_Donor = R1.RN_Donor - 1
    left join Results_Temp P2 on P2.Donor_Number = R1.Donor_Number and P2.Rn_Donor = R1.RN_Donor - 2
    Select *
    , case when PrevDon1 in (9, 10, 11) and PrevDon2 in (9, 10, 11) then 'Q'
    when PrevDon1 in (9, 10, 11) then 'A2'
    when PrevDon1 is not null then 'A1'
    End as NEWSTATUS
    from Results_Interim
    Where Test_result_Date >= '2014-01' and Test_result_Date < '2014-02'
    Order by Donor_Number, donation_date

  • Problem with SQL Insert

    Hi
    I am using Flex to insert data through remoteobject and using
    SAVE method generated from CFC Wizard.
    My VO contains the following variables where id has a default
    value of 0 :
    public var id:Number = 0 ;
    public var date:String = "";
    public var accountno:String = "";
    public var debit:Number = 0;
    public var credit:Number = 0;
    id is set as the primary key in my database.
    I have previously used MySQL which automatically generates a
    new id if I either omitted the id value in my insert statement or
    use 0 as the default value.
    However, now I am using MS SQL Server and the insert
    generated this error:
    Unable to invoke CFC - Error Executing Database Query.
    Detail:
    [Macromedia][SQLServer JDBC Driver][SQLServer]Cannot insert
    explicit value for identity column in table 'Transactions' when
    IDENTITY_INSERT is set to OFF.
    Strange thing is that I dont see this problem with another
    sample application. I compared with that application (it has the
    same VO with default value of 0 for id) and everything looks
    similar so I can't understand why I have this error in my
    application.
    This is SQL used to create the table:
    USE [Transactions]
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    SET ANSI_PADDING ON
    CREATE TABLE [dbo].[Transactions](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [date] [datetime] NULL,
    [accountno] [varchar](100) NULL,
    [debit] [int] NULL,
    [credit] [int] NULL,
    CONSTRAINT [PK_Transactions] PRIMARY KEY CLUSTERED
    [id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE =
    OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
    ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    Has anyone encountered this problem before with insert
    statements dealing with a unique id (with MS SQL Server)?

    Change "addRecords =
    connection.prepareStatement("
    to "addRecords =
    connection.preparedStatement("
    -BIGD

  • How to update date in a table from another database

    Hello,
    I am trying to code a way to Update my Testing database from another database. In the coding below the database that has the updated data ends in Restore.
    Use ClientDB_MASTER_Restore
    Truncate Table ClientDB_MASTER_Testing.dbo.Activity_Tracking_AZ
    GO
    SELECT * INTO ClientDB_Master_Testing.dbo.Activity_Tracking_AZ
    FROM Activity_Tracking_AZ
    Go
    I know with this Technique the table must be truncated if not deleted first.  There is probably a better way to do this which I'm very open to.  I'm also looking for coding that will roll back any changes made should an error occur.
      As always, any help is greatly appreciated.
    David92595

    USE ClientDB_MASTER_Testing
    go
    SET XACT_ABORT ON
    BEGIN TRANSACTION
    Truncate Table dbo.Activity_Tracking_AZ
    -- SET IDENTITY_INSERT dbo.Activity_Tracking_AZ ON
    INSERT dbo.Activity_Tracking_AZ (col1, col2, ...)
    SELECT col1, col2,
    FROM ClientDB_MASTER_Restore.dbo.Activity_Tracking_AZ
    -- SET IDENTITY_INSERT dbo.Activity_Tracking_AZ OFF
    COMMIT TRANSACTION
    If you find it boring to type the column lists, just find the table in Object Explorer, and drag the columns node to where you want the column list.
    You need the SET IDENTITY_INSERT command if the table has an IDENTITY column.
    By wrapping the code in a transaction, you are not left with an empty table if the INSERT fails. The command SET XACT_ABORT ON makes sure that the batch is aborted and rolled back in case of an error.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Aging Report SQL Query

    Dear Guys,
    I have tried for aging report query , but still my expected results is not come. Please go through below the table and script data for your reference. Please wirte a query for aging report.
    USE [SAMPLES]
    GO
    /****** Object: Table [dbo].[NEW_DCB_REPORT] Script Date: 02/12/2015 01:19:06 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_PADDING OFF
    GO
    CREATE TABLE [dbo].[NEW_DCB_REPORT](
    [MFDB_LedgerNumber] [int] IDENTITY(1,1) NOT NULL,
    [MFDB_TxnDate] [datetime] NOT NULL,
    [MFDB_StateId] [int] NOT NULL,
    [MFDB_RegionId] [int] NOT NULL,
    [MFDB_BranchId] [int] NOT NULL,
    [MFDB_SHGId] [int] NOT NULL,
    [MFDB_SHGName] [varchar](75) NOT NULL,
    [MFDB_ShgMemberId] [int] NOT NULL,
    [MFDB_MemberName] [varchar](50) NOT NULL,
    [MFDB_VillageId] [int] NOT NULL,
    [MFDB_LoanNumber] [int] NOT NULL,
    [MFDB_LoanAmount] [int] NOT NULL,
    [MFDB_DisbursedDate] [datetime] NOT NULL,
    [MFDB_DemandDate] [datetime] NULL,
    [MFDB_CollectionDate] [datetime] NULL,
    [MFDB_InstallmentNumber] [int] NOT NULL,
    [MFDB_ArrearPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_ArrearInterest] [numeric](18, 2) NOT NULL,
    [MFDB_DemandPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_DemandInterest] [numeric](18, 2) NOT NULL,
    [MFDB_TotDemandPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_TotDemandInterest] [numeric](18, 2) NOT NULL,
    [MFDB_AdvOBPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_AdvOBInterest] [numeric](18, 2) NOT NULL,
    [MFDB_CollectedPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_CollectedInterest] [numeric](18, 2) NOT NULL,
    [MFDB_AdvCBPrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_AdvCBInterest] [numeric](18, 2) NOT NULL,
    [MFDB_BalancePrincipal] [numeric](18, 2) NOT NULL,
    [MFDB_BalanceInterest] [numeric](18, 2) NOT NULL,
    [MFDB_OS_Pri] [numeric](18, 2) NOT NULL,
    [MFDB_OS_Int] [numeric](18, 2) NOT NULL,
    [MFDB_RepaymentPercentage] [int] NOT NULL,
    [MFDB_LoanSchemeId] [int] NOT NULL,
    [MFDB_LActivityId] [int] NOT NULL,
    [MFDB_LActSpecId] [int] NOT NULL,
    [MFDB_FundAgencyId] [int] NOT NULL,
    [MFDB_LSourceId] [int] NOT NULL,
    [MFDB_Months] [varchar](15) NOT NULL,
    [MFDB_PanchayatId] [int] NOT NULL,
    [MFDB_PanchayatName] [varchar](100) NOT NULL,
    [MFDB_VillageName] [varchar](100) NOT NULL
    ) ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    USE [SAMPLES];
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    GO
    SET IDENTITY_INSERT [dbo].[NEW_DCB_REPORT] ON;
    BEGIN TRANSACTION;
    INSERT INTO [dbo].[NEW_DCB_REPORT]([MFDB_LedgerNumber], [MFDB_TxnDate], [MFDB_StateId], [MFDB_RegionId], [MFDB_BranchId], [MFDB_SHGId], [MFDB_SHGName], [MFDB_ShgMemberId], [MFDB_MemberName], [MFDB_VillageId], [MFDB_LoanNumber], [MFDB_LoanAmount], [MFDB_DisbursedDate], [MFDB_DemandDate], [MFDB_CollectionDate], [MFDB_InstallmentNumber], [MFDB_ArrearPrincipal], [MFDB_ArrearInterest], [MFDB_DemandPrincipal], [MFDB_DemandInterest], [MFDB_TotDemandPrincipal], [MFDB_TotDemandInterest], [MFDB_AdvOBPrincipal], [MFDB_AdvOBInterest], [MFDB_CollectedPrincipal], [MFDB_CollectedInterest], [MFDB_AdvCBPrincipal], [MFDB_AdvCBInterest], [MFDB_BalancePrincipal], [MFDB_BalanceInterest], [MFDB_OS_Pri], [MFDB_OS_Int], [MFDB_RepaymentPercentage], [MFDB_LoanSchemeId], [MFDB_LActivityId], [MFDB_LActSpecId], [MFDB_FundAgencyId], [MFDB_LSourceId], [MFDB_Months], [MFDB_PanchayatId], [MFDB_PanchayatName], [MFDB_VillageName])
    SELECT 18, '20140422 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', NULL, NULL, 0, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Apr - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 162, '20140521 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140521 00:00:00.000', NULL, 1, 0.00, 0.00, 0.00, 150.00, 0.00, 150.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 150.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'May - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 13932, '20140621 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140621 00:00:00.000', NULL, 2, 0.00, 150.00, 909.00, 150.00, 909.00, 300.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 909.00, 300.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Jun - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 32505, '20140721 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140721 00:00:00.000', NULL, 3, 909.00, 300.00, 909.00, 136.00, 1818.00, 436.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1818.00, 436.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Jul - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 62524, '20140821 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140821 00:00:00.000', NULL, 4, 1818.00, 436.00, 909.00, 123.00, 2727.00, 559.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 2727.00, 559.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Aug - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 100871, '20140921 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20140921 00:00:00.000', NULL, 5, 2727.00, 559.00, 909.00, 109.00, 3636.00, 668.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 3636.00, 668.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Sep - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 153679, '20141021 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20141021 00:00:00.000', NULL, 6, 3636.00, 668.00, 909.00, 96.00, 4545.00, 764.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 4545.00, 764.00, 10000.00, 1051.00, 0, 3, 4, 77, 3, 2, N'Oct - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 203840, '20141119 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', NULL, '20141119 00:00:00.000', 2, 4545.00, 764.00, 0.00, 0.00, 4545.00, 764.00, 0.00, 0.00, 10000.00, 150.00, 5455.00, 0.00, 0.00, 614.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Nov - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 291259, '20141221 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20141221 00:00:00.000', NULL, 8, 0.00, 614.00, 909.00, 68.00, 909.00, 682.00, 5455.00, 0.00, 0.00, 0.00, 4546.00, 0.00, 0.00, 682.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Dec - 14', 2927, N'PALI', N'PALI' UNION ALL
    SELECT 363176, '20150121 00:00:00.000', 6, 16, 67, 5514, N'MAHALAXMI-5514', 66735, N'SUNITA', 4624, 1, 10000, '20140422 00:00:00.000', '20150121 00:00:00.000', NULL, 9, 0.00, 682.00, 909.00, 55.00, 909.00, 737.00, 4546.00, 0.00, 0.00, 0.00, 3637.00, 0.00, 0.00, 737.00, 0.00, 901.00, 0, 3, 4, 77, 3, 2, N'Jan - 15', 2927, N'PALI', N'PALI'
    COMMIT;
    RAISERROR (N'[dbo].[NEW_DCB_REPORT]: Insert Batch: 1.....Done!', 10, 1) WITH NOWAIT;
    GO
    SET IDENTITY_INSERT [dbo].[NEW_DCB_REPORT] OFF;
    I expected results as below:
    Report As On Date: 30-10-2014
    S.No. SHG NAME MEMBER NAME <=30 31-60 61-90 91-120 91-180 181-365 365 - 689 Above 2 Yrs
    1 MAHALAXMI-5514 SUNITA 0 909 1818 2727 3636 4545 0 0
    Report As On Date:
    30-10-2014
    S.No.
    SHG NAME
    MEMBER NAME
    <=30
    31-60
    61-90
    91-120
    91-180
    181-365
    365 - 689
    Above 2 Yrs
    1
    MAHALAXMI-5514
    SUNITA
    0
    909
    1818
    2727
    3636
    4545
    0
    0

    Thanks for your replay,  I have checked your query it seems nearly ok, Please find my script which i tried above for the same.
    DECLARE @i_AsOnDate AS DATETIME = '2014-09-30'
    ;WITH CA1 AS
    SELECT ROW_NUMBER() OVER(Order  By DR.MFDB_SHGName,DR.MFDB_MemberName)
    AS SerialNumber,
      DR.MFDB_SHGId
    AS ShgId,
      DR.MFDB_SHGName
    AS ShgName,
      DR.MFDB_ShgMemberId
    AS MemId,
      DR.MFDB_MemberName
    AS MemName,
      ISNULL((SELECT CAST(SUM(LD.MFDB_StdPrincipal) AS BIGINT )
      FROM  MFDB_LOAN_DISBURSEMENT LD
      WHERE LD.MFDB_SHGId
    = DR.MFDB_SHGId 
      AND   LD.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId 
      AND   LD.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
      AND   LD.MFDB_ApprovalStatus = 1
      AND   DATEDIFF(DAY,@i_AsOnDate,LD.MFDB_CollectionDate) > 0 ),0)
    AS YETDUE,
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) >= 0
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 30
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '0-30',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 60 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 30
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '31-60',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 90 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 60
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '61-90',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 120 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 90
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '91-120',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 180 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 120
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '121-180',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 365 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 180
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '181-365',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 689 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 365
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS '366-689',
    ISNULL((SELECT TOP 1 CAST(ND.MFDB_BalancePrincipal AS BIGINT )
    FROM dbo.MFDB_NEW_DCB_REPORT ND
    WHERE ND.MFDB_SHGId
    = DR.MFDB_SHGId 
    AND   ND.MFDB_ShgMemberId
    = DR.MFDB_ShgMemberId  
    AND   ND.MFDB_LoanNumber
    = DR.MFDB_LoanNumber
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) <= 730 
    AND   DATEDIFF(Day,ND.MFDB_TxnDate,@i_AsOnDate) > 689
    ORDER BY ND.MFDB_LedgerNumber DESC),0)
    AS 'Above_2_Yrs'   
    FROM DBO.MFDB_NEW_DCB_REPORT DR
    WHERE DR.MFDB_BranchId
    = 67
    AND   DR.MFDB_SHGId
    IN (5514)
    AND   DR.MFDB_ShgMemberId = 66735
    AND   DATEDIFF(DAY,MFDB_TxnDate,@i_AsOnDate) >= 0  
    SELECT * FROM CA1
    results after the execution of the script:
    SerialNumber
    ShgId
    ShgName
    MemId
    MemName
    YETDUE
    0-30
    31-60
    61-90
    91-120
    121-180
    181-365
    366-689
    Above_2_Yrs
    3
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    2
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    6
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    4
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    1
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    5
    5514
    MAHALAXMI-5514
    SUNITA
    10000
    3636
    2727
    1818
    909
    0
    0
    0
    0
    But I expected results is:
    s.n
    ShgId
    ShgName
    MemId
    MemName
    YETDUE
    0-30
    31-60
    61-90
    91-120
    121-180
    181-365
    366-689
    Above_2_Yrs
    1
    5514
    MAHALAXMI-5514
    66735
    SUNITA
    10000
    909
    1818
    2727
    3636
    0
    0
    0
    I want only one record per member with aging .. please advice me for further action.

  • Errors in visual studio webpage code (Trying to connect the website to a database)

    I am trying to create a website on (visual studio) and connect it to database(Microsoft sql server 2014) first I am learning from a video on youtube the tutorial is about a coffee website and database
    I have a few errors but I dont know where is the problem
    the errors in this page(Coffee.aspx.cs)
    Error    1    Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).    C:\Users\Ziyad 1\Documents\Visual Studio
    2013\WebSites\MyWebsite\Pages\Coffee.aspx.cs    7    33    MyWebsite
    Error    4    'ASP.pages_coffee_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override    c:\Users\Ziyad 1\AppData\Local\Temp\Temporary ASP.NET Files\root\e78a0b4c\be391a08\App_Web_k4b10ys2.0.cs  
     572    
    Error    3    'ASP.pages_coffee_aspx.GetTypeHashCode()': no suitable method found to override    c:\Users\Ziyad 1\AppData\Local\Temp\Temporary ASP.NET Files\root\e78a0b4c\be391a08\App_Web_k4b10ys2.0.cs  
     567    
    Error    5    'ASP.pages_coffee_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'    c:\Users\Ziyad 1\AppData\Local\Temp\Temporary ASP.NET Files\root\e78a0b4c\be391a08\App_Web_k4b10ys2.0.cs  
     185    
    and here is the page (Coffee.aspx.cs) code
    using System;
    using System.Collections;
    using System.Text;
    namespace Pages
    public partial class Pages_Coffee : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    FillPage();
    private void FillPage()
    ArrayList coffeeList = ConnectionClass.GetCoffeeByType(DropDownList1.SelectedValue);
    StringBuilder sb = new StringBuilder();
    foreach (Coffee coffee in coffeeList)
    sb.Append(
    string.Format(
    @"<table class='coffeeTable'>
    <tr>
    <th rowspan='6' width='150px'><img runat='server' src='{6}' /></th>
    <th width='50px'>Name: </td>
    <td>{0}</td>
    </tr>
    <tr>
    <th>Type: </th>
    <td>{1}</td>
    </tr>
    <tr>
    <th>Price: </th>
    <td>{2} $</td>
    </tr>
    <tr>
    <th>Roast: </th>
    <td>{3}</td>
    </tr>
    <tr>
    <th>Origin: </th>
    <td>{4}</td>
    </tr>
    <tr>
    <td colspan='2'>{5}</td>
    </tr>
    </table>", coffee.Name, coffee.Type, coffee.Price, coffee.Roast, coffee.Country, coffee.Review, coffee.Image));
    lblOuput.Text = sb.ToString();
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    FillPage();
    also tis is the page (Coffee.aspx)code
    <%@ Page Title="" Language="C#" MasterPageFile="~/Masterpage.master" AutoEventWireup="true" CodeFile="Coffee.aspx.cs" Inherits="Coffee" %>
    <script runat="server">
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    </script>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
    Select a type:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="sds_type" DataTextField="type" DataValueField="type" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>
    <asp:SqlDataSource ID="sds_type" runat="server" ConnectionString="<%$ ConnectionStrings:CoffeeDBConnectionString %>" SelectCommand="SELECT DISTINCT [type] FROM [coffee] ORDER BY [type]"></asp:SqlDataSource>
    </p>
    <p>
    <asp:Label ID="lblOutput" runat="server" Text="Label"></asp:Label>
    </p>
    </asp:Content>
    this is th (ConnectionClass.cs)code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Collections;
    using System.Configuration;
    using System.Data.SqlClient;
    public static class ConnectionClass
    private static SqlConnection conn;
    private static SqlCommand command;
    static ConnectionClass()
    string connectionString =
    ConfigurationManager.ConnectionStrings["coffeeConnection"].ToString();
    conn = new SqlConnection(connectionString);
    command = new SqlCommand("", conn);
    public static ArrayList GetCoffeeByType(string coffeeType)
    ArrayList list = new ArrayList();
    string query = string.Format("SELECT * FROM coffee WHERE type LIKE '{0}'", coffeeType);
    try
    conn.Open();
    command.CommandText = query;
    SqlDataReader reader = command.ExecuteReader();
    while (reader.Read())
    int id = reader.GetInt32(0);
    string name = reader.GetString(1);
    string type = reader.GetString(2);
    double price = reader.GetDouble(3);
    string roast = reader.GetString(4);
    string country = reader.GetString(5);
    string image = reader.GetString(6);
    string review = reader.GetString(7);
    Coffee coffee = new Coffee(id, name, type, price, roast, country, image, review);
    list.Add(coffee);
    finally
    conn.Close();
    return list;
    (web.confg)code
    <?xml version="1.0"?>
    <configuration>
    <appSettings/>
    <connectionStrings>
    <clear/>
    <add name="coffeeConnection"
    connectionString="Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=CoffeeDB;Integrated Security=True"
    providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
    <compilation debug="true" targetFramework="4.0">
    <assemblies>
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
    </compilation>
    <authentication mode="Windows"/>
    </system.web>
    </configuration>
    and finally this is the SQL code
    GO
    CREATE TABLE [dbo].[coffee](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [name] [varchar](50) NOT NULL,
    [type] [varchar](50) NOT NULL,
    [price] [float] NOT NULL,
    [roast] [varchar](50) NOT NULL,
    [country] [varchar](50) NOT NULL,
    [image] [varchar](255) NULL,
    [review] [text] NOT NULL,
    PRIMARY KEY CLUSTERED
    [id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    SET ANSI_PADDING OFF
    GO
    SET IDENTITY_INSERT [dbo].[coffee] ON
    INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country], [image], [review]) VALUES (1, N'Café au Lait', N'Classic', 2.25, N'Medium', N'France', N'../Images/Coffee/Cafe-Au-Lait.jpg', N'A coffee beverage consisting strong or bold coffee (sometimes espresso) mixed with scalded milk in approximately a 1:1 ratio.')
    INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country], [image], [review]) VALUES (2, N'Caffè Americano', N'Espresso', 2.25, N'Medium', N'Italy', N'../Images/coffee/caffe_americano.jpg', N'Similar in strength and taste to American-style brewed coffee, there are subtle differences achieved by pulling a fresh shot of espresso for the beverage base.')
    INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country], [image], [review]) VALUES (3, N'Peppermint White Chocolate Mocha', N'Espresso', 3.25, N'Medium', N'Italy', N'../Images/coffee/white-chocolate-peppermint-mocha.jpg', N'Espresso with white chocolate and peppermint flavored syrups.
    Topped with sweetened whipped cream and dark chocolate curls.')
    INSERT [dbo].[coffee] ([id], [name], [type], [price], [roast], [country], [image], [review]) VALUES (4, N'Irish Coffee', N'Alcoholic', 2.25, N'Dark', N'Ireland', N'../Images/coffee/irish coffee.jpg', N'A cocktail consisting of hot coffee, Irish whiskey, and sugar, stirred, and topped with thick cream. The coffee is drunk through the cream.')
    SET IDENTITY_INSERT [dbo].[coffee] OFF
    I am still a beginner ~~ I need to understand what are these errors and how to solve them

    Hello,
    Welcome to MSDN forum.
    I am afraid that the issue is out of support range of VS General Question forum which mainly discusses
    the usage of Visual Studio IDE such as WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    Because your issue is about website, I suggest that you can consult your issue on ASP.NET forum:
    http://forums.asp.net/
     for better solution and support.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Error when inserting in a table with an identity column

    Hi,
    I am new to Oracle SOA suite and ESB.
    I have been through the Oracle training and have worked for about 2 months with the tooling.
    We have a Database adabter that inserts data in 5 Tables with relations to each other.
    Each table has his own not NULL Identity column.
    When running/ testing the ESB service we get the error at the end of this post.
    From this we learned that the Database adapter inserts the value NULL in the identity column.
    We cannot find in the documentation how to get the database adabter to skip this first column and ignore it.
    Is this possible within the wizard? Our impression is no
    Is this possible somwhere else/
    And if so How can we do this?
    If anyone can help it would be greatly appreciated
    Pepijn
    Generic error.
    oracle.tip.esb.server.common.exceptions.BusinessEventRejectionException: An unhandled exception has been thrown in the ESB system. The exception reported is: "org.collaxa.thirdparty.apache.wsif.WSIFException: esb:///ESB_Projects/GVB_PDI_PDI_Wegschrijven_Medewerkergegevens/testurv.wsdl [ testurv_ptt::insert(VastAdresCollection) ] - WSIF JCA Execute of operation 'insert' failed due to: DBWriteInteractionSpec Execute Failed Exception.
    insert failed. Descriptor name: [testurv.VastAdres]. [Caused by: Cannot insert explicit value for identity column in table 'VastAdres' when IDENTITY_INSERT is set to OFF.]
    ; nested exception is:
         ORABPEL-11616
    DBWriteInteractionSpec Execute Failed Exception.
    insert failed. Descriptor name: [testurv.VastAdres]. [Caused by: Cannot insert explicit value for identity column in table 'VastAdres' when IDENTITY_INSERT is set to OFF.]
    Caused by Uitzondering [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.3.0) (Build 070608)): oracle.toplink.exceptions.DatabaseException
    Interne uitzondering: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table 'VastAdres' when IDENTITY_INSERT is set to OFF.Foutcode: 544
    Call:INSERT INTO dbo.VastAdres (ID, BeginDatum, Einddatum, Land, Plaats, Postcode, VolAdres) VALUES (?, ?, ?, ?, ?, ?, ?)
         bind => [null, 1894-06-24 00:00:00.0, 1872-09-04 00:00:00.0, Nederland, Wijdewormer, 1456 NR, Oosterdwarsweg 8]
    Query:InsertObjectQuery(<VastAdres null />).

    Hi,
    Click on the resources tab in the ESB system/ Project to see the ESB system design and all the components in it.
    Click on the Database adapter that you want to edit..and make the necesary changes..
    Check this link.
    http://download-uk.oracle.com/docs/cd/B31017_01/core.1013/b28764/esb008.htm for "6.8.2 How to Modify Adapter Services" section.
    If you are calling a database procedure which inturn makes the insert, you will have to make changes in the database and you job would be much simpler. It seems there are limitations on what you can change in the Database adapter once it is created. Please check the link for further details.
    Thanks,
    Rajesh

  • RE:ora-28500 when trying to insert into SQL Server table

    Hi all!
    I'm getting this when i attempt to insert into my table test in a SQL Server database. As u can see from the select, the database link seems ok. Any ideas plz. Thnx..
    SQL> select "idAges" from test@try2;
    no rows selected
    SQL> insert into test@try2 ("idAges","nARAges","nAPAges") values(10,'','');
    insert into test@try2 ("idAges","nARAges","nAPAges") values(10,'','')
    ERROR at line 1:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Generic Connectivity Using ODBC][Microsoft][ODBC SQL Server Driver][SQL
    Server]Cannot insert explicit value for identity column in table 'test' when
    IDENTITY_INSERT is set to OFF. (SQL State: 23000; SQL Code: 544)
    ORA-02063: preceding 2 lines from TRY2

    IDENTITY_INSERT on works only for particular session and for one table. It's not global variable.
    The only idea what I have is to create link from MS Sql to Oracle (right now You have oracle ->ms sql)and then before insert You will set identity_insert on and will run insert.

  • 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

  • How can i get the parent value by sum of the child value of billing of material by using with cte

    I want to sum every parent recursively to the top of parent for example
    So far i got all relation between parent and child
    but I can t get the sum value of all parent in every levels ,
    This is what i get so far 
     WITH EmpCTE( MS_ID ,  MMS_ID , Qty , FLG , lvl)
                        AS
                        SELECT        Child_Code, Parent_Code , Cast(1 as float) ,  GSS_HR_COSTRELATION.FLG  , 0 AS lvl
                        FROM            GSS_HR_COSTRELATION
                        WHERE Child_Code  =  '01'
                        UNION ALL
                        SELECT        Child_Code, Parent_Code , Cast(1 as float) , E.FLG  , M.lvl + 1
                        FROM            GSS_HR_COSTRELATION AS E
                        JOIN EmpCTE AS M  ON E.Parent_Code = M.MS_ID WHERE  E.FLG is null
                        SELECT  A.Cost_ID , MS_ID  , A.Cost_CODE , A.Cost_name ,  MMS_ID , FLG , ISNULL(A.TOTAL , 0) As Cost , Cast(A.month AS nvarchar) As month , lvl From EmpCTE  LEFT join
                        SELECT  Cost_ID , Cost_CODE , Cost_Name ,  Sum(QTY*PRICE) AS TOTAL ,month(DateCreated) AS month
                        FROM            GSS_HR_COSTCENTER LEFT JOIN
                        GSS_AC_WTHDRAW ON GSS_HR_COSTCENTER.Cost_ID = GSS_AC_WTHDRAW.line_id
                        GROUP BY Cost_ID , Cost_Name , Cost_CODE ,month(DateCreated) ) A ON A.Cost_code = EmpCTE.MS_ID Order by lvl , A.Cost_CODE
    Thanks
    I am using Sql server 2012 
    this is my script of my database (include data)
    USE [SMEDB]
    GO
    /****** Object:  Table [dbo].[GSS_AC_WTHDRAW]    Script Date: 11/23/2014 3:31:31 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[GSS_AC_WTHDRAW](
    [MATID] [int] IDENTITY(1,1) NOT NULL,
    [MATNO] [nvarchar](50) NULL,
    [STPRICE_ID] [int] NULL,
    [MS_CD] [nvarchar](50) NULL,
    [QTY] [decimal](16, 2) NULL,
    [PRICE] [float] NULL,
    [DateCreated] [datetime] NULL,
    [Name] [nvarchar](50) NULL,
    [DeptID] [int] NULL,
    [CreatedID_by] [int] NULL,
    [JvHeader_ID] [int] NULL,
    [line_id] [int] NULL,
    [createby] [nvarchar](50) NULL,
     CONSTRAINT [PK_GSS_AC_WTHDRAW] PRIMARY KEY CLUSTERED 
    [MATID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    /****** Object:  Table [dbo].[GSS_HR_COSTCENTER]    Script Date: 11/23/2014 3:31:31 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[GSS_HR_COSTCENTER](
    [Cost_ID] [int] IDENTITY(1,1) NOT NULL,
    [Cost_code] [nvarchar](50) NOT NULL,
    [Cost_name] [nvarchar](50) NULL,
    [Dept_ID] [int] NULL,
    [DeptGroup_ID] [int] NULL,
     CONSTRAINT [PK_GSS_HR_COSTCENTER] PRIMARY KEY CLUSTERED 
    [Cost_code] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    /****** Object:  Table [dbo].[GSS_HR_COSTRELATION]    Script Date: 11/23/2014 3:31:31 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[GSS_HR_COSTRELATION](
    [Relation_ID] [int] IDENTITY(1,1) NOT NULL,
    [Child_Code] [nvarchar](50) NULL,
    [Parent_Code] [nvarchar](50) NULL,
    [FLG] [int] NULL
    ) ON [PRIMARY]
    GO
    SET IDENTITY_INSERT [dbo].[GSS_AC_WTHDRAW] ON 
    INSERT [dbo].[GSS_AC_WTHDRAW] ([MATID], [MATNO], [STPRICE_ID], [MS_CD], [QTY], [PRICE], [DateCreated], [Name], [DeptID], [CreatedID_by], [JvHeader_ID], [line_id], [createby]) VALUES (1002, N'1411-0130', 1385, N'9101101', CAST(200.00 AS Decimal(16, 2)), 18,
    CAST(0x0000A3DB00000000 AS DateTime), N'0', 13, NULL, NULL, 49, NULL)
    INSERT [dbo].[GSS_AC_WTHDRAW] ([MATID], [MATNO], [STPRICE_ID], [MS_CD], [QTY], [PRICE], [DateCreated], [Name], [DeptID], [CreatedID_by], [JvHeader_ID], [line_id], [createby]) VALUES (1003, N'1411-0130', 1466, N'910201', CAST(50.00 AS Decimal(16, 2)), 18, CAST(0x0000A3DB00000000
    AS DateTime), N'0', 13, NULL, NULL, 49, NULL)
    INSERT [dbo].[GSS_AC_WTHDRAW] ([MATID], [MATNO], [STPRICE_ID], [MS_CD], [QTY], [PRICE], [DateCreated], [Name], [DeptID], [CreatedID_by], [JvHeader_ID], [line_id], [createby]) VALUES (1004, N'1411-0131', 1456, N'914201', CAST(150.00 AS Decimal(16, 2)), 27.25,
    CAST(0x0000A3DB00000000 AS DateTime), N'0', 13, NULL, NULL, 58, NULL)
    INSERT [dbo].[GSS_AC_WTHDRAW] ([MATID], [MATNO], [STPRICE_ID], [MS_CD], [QTY], [PRICE], [DateCreated], [Name], [DeptID], [CreatedID_by], [JvHeader_ID], [line_id], [createby]) VALUES (1005, N'1411-0131', 1118, N'914016', CAST(31.00 AS Decimal(16, 2)), 105, CAST(0x0000A3DB00000000
    AS DateTime), N'0', 13, NULL, NULL, 59, NULL)
    INSERT [dbo].[GSS_AC_WTHDRAW] ([MATID], [MATNO], [STPRICE_ID], [MS_CD], [QTY], [PRICE], [DateCreated], [Name], [DeptID], [CreatedID_by], [JvHeader_ID], [line_id], [createby]) VALUES (1006, N'1411-0131', 105, N'914015', CAST(34.00 AS Decimal(16, 2)), 70, CAST(0x0000A3DB00000000
    AS DateTime), N'0', 13, NULL, NULL, 59, NULL)
    SET IDENTITY_INSERT [dbo].[GSS_AC_WTHDRAW] OFF
    SET IDENTITY_INSERT [dbo].[GSS_HR_COSTCENTER] ON 
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (107, N'01', N'SME', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (1, N'02', N'ADMIN', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (2, N'03', N'MANUFACTURE', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (15, N'11', N'Pattern', 11, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (104, N'21', N'Foundry', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (16, N'2100', N'FD Common', NULL, 2)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (41, N'2110', N'Melting', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (108, N'2110-00', N'Melting Common', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (123, N'2110-01', N'Melting Repairing', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (109, N'2110-01-0101', N'Melting_เตา.1', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (124, N'2110-01-0201', N'Melting CM1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (125, N'2110-01-0202', N'Melting CM2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (126, N'2110-01-0203', N'Melting CM3', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (127, N'2110-01-0204', N'Melting CM4', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (128, N'2110-01-0205', N'Melting CM5', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (129, N'2110-01-0206', N'Melting CM6', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (130, N'2110-01-0207', N'Melting CM7', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (131, N'2110-01-0208', N'Melting CM8', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (132, N'2110-01-0209', N'Melting CM9', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (110, N'2110-02-0102', N'Melting_เตา.2', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (111, N'2110-03-0103', N'Melting_เตา.3', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (112, N'2110-04-0104', N'Melting_เตา.4', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (113, N'2110-05-0105', N'Melting_เตา.5', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (114, N'2110-06-0106', N'Melting_เตา.6', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (115, N'2110-07-0107', N'Melting_เตา.7', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (116, N'2110-08-0108', N'Melting_เตา.8', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (117, N'2110-09-0109', N'Melting_เตา.9', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (118, N'2110-10-0110', N'Melting_เตา.10', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (119, N'2110-11-0111', N'Melting_เตา.11', 12, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (18, N'2111', N'Molding', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (42, N'2111-01', N'Core Common', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (151, N'2111-01-0201', N'Moulding -Core _CSC1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (152, N'2111-01-0202', N'Moulding -Core _CSC2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (148, N'2111-01-0401', N'Moulding -Core _CS-1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (149, N'2111-01-0402', N'Moulding -Core _CS-2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (150, N'2111-01-0501', N'Moulding -Core _MP-1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (43, N'2111-0110', N'Core - HSP', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (44, N'2111-0111', N'Core - AVS', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (45, N'2111-0112', N'Core - VML', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (46, N'2111-0113', N'Core - AMF', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (47, N'2111-0114', N'Core - DISA', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (48, N'2111-02', N'Molding Line Common', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (49, N'2111-0210', N'Molding Line - HSP', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (144, N'2111-0210-0201', N'Moulding Line-HSP_CHSP1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (145, N'2111-0210-0202', N'Moulding Line-HSP_CHSP2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (146, N'2111-0210-0203', N'Moulding Line-HSP_CHSP3', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (143, N'2111-0210-0301', N'Moulding Line-HSP_HSP', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (50, N'2111-0211', N'Molding Line - AVS', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (139, N'2111-0211-0201', N'Moulding Line-AVS_CAVS', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (140, N'2111-0211-0202', N'Moulding Line-AVS_CAV1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (141, N'2111-0211-0203', N'Moulding Line-AVS_CAV2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (142, N'2111-0211-0204', N'Moulding Line-AVS_CAV3', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (138, N'2111-0211-0301', N'Moulding Line-AVS_AVS', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (51, N'2111-0212', N'Molding Line - VML', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (137, N'2111-0212-0201', N'Moulding Line-VML_CVML', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (136, N'2111-0212-0301', N'Moulding Line-VML_VML', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (52, N'2111-0213', N'Molding Line - AMF', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (134, N'2111-0213-0201', N'Moulding Line-AMF_CAMF1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (135, N'2111-0213-0202', N'Moulding Line-AMF_CAMF2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (133, N'2111-0213-0301', N'Moulding Line-AMF_AMF', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (53, N'2111-0214', N'Molding Line - DISA', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (147, N'2111-0214-0301', N'Moulding Line-DISA_DISA', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (54, N'2111-0215', N'Finishing Small - Shot Blast', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (55, N'2111-0216', N'Finishing Small - Grinding', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (159, N'2111-0216-1101', N'Moulding-Finishing-small grinding_G1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (160, N'2111-0216-1102', N'Moulding-Finishing-small grinding_G2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (161, N'2111-0216-1103', N'Moulding-Finishing-small grinding_G3', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (162, N'2111-0216-1104', N'Moulding-Finishing-small grinding_G4', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (163, N'2111-0216-1105', N'Moulding-Finishing-small grinding_G5', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (164, N'2111-0216-1106', N'Moulding-Finishing-small grinding_G6', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (165, N'2111-0216-1107', N'Moulding-Finishing-small grinding_G7', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (166, N'2111-0216-1108', N'Moulding-Finishing-small grinding_G8', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (167, N'2111-0216-1109', N'Moulding-Finishing-small grinding_G9', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (168, N'2111-0216-1110', N'Moulding-Finishing-small grinding_G10', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (56, N'2111-0217', N'Finishing Small - Oil Painting', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (57, N'2111-0218', N'Finishing Small - Packing', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (58, N'2111-0219', N'Finishing Line - Shot Blast', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (153, N'2111-0219-0901', N'Moulding-Finishing Line Shot Blast_SB-1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (154, N'2111-0219-0902', N'Moulding-Finishing Line Shot Blast_SB-2', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (155, N'2111-0219-0903', N'Moulding-Finishing Line Shot Blast_SB-3', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (156, N'2111-0219-0904', N'Moulding-Finishing Line Shot Blast_SB-4', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (157, N'2111-0219-0905', N'Moulding-Finishing Line Shot Blast_SB-5', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (158, N'2111-0219-0906', N'Moulding-Finishing Line Shot Blast_SB-6', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (59, N'2111-0220', N'Finishing Line - Grinding', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (60, N'2111-0221', N'Finishing Line - Oil Painting', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (61, N'2111-0222', N'Finishing Line - Packing', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (62, N'2111-03', N'Molding Repairing', 13, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (19, N'2112', N'F1', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (63, N'2112-00', N'F1 Common', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (64, N'2112-01', N'Molding Roll', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (65, N'2112-0110', N'Grinding Roll', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (66, N'2112-02', N'Molding M/C Tool', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (67, N'2112-0210', N'Finishing F1', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (68, N'2112-0211', N'Shot Blast F1', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (69, N'2112-0212', N'Grinding F1', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (70, N'2112-0213', N'Painting F1', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (71, N'2112-0214', N'Packing F1', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (72, N'2112-0215', N'Repairing F1', 14, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (20, N'2113', N'F2', NULL, NULL)
    GO
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (73, N'2113-00', N'F2 Common', 15, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (74, N'2113-01', N'Molding Press Die', 15, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (75, N'2113-02', N'Finishing F2', 15, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (76, N'2113-03', N'Shot Blast F2', 15, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (77, N'2113-04', N'Grinding F2', 15, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (78, N'2113-05', N'Painting F2', 15, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (79, N'2113-06', N'Repairing F2', 15, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (105, N'51', N'Machine', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (21, N'5100', N'MC Common', NULL, 3)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (22, N'5110', N'SME M/C', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (80, N'5110-00', N'SME M/C Common', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (81, N'5110-01', N'SME M/C CNC Late', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (82, N'5110-02', N'M/C Center', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (83, N'5110-03', N'Timing', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (84, N'5110-04', N'Milling', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (85, N'5110-05', N'SME M/C Grinding', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (86, N'5110-06', N'Drilling', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (87, N'5110-07', N'Boring', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (88, N'5110-08', N'Honning', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (89, N'5110-09', N'Double Colume', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (90, N'5110-10', N'Painting', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (91, N'5110-11', N'SME M/C Packing', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (23, N'5111', N'ROLL M/C', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (92, N'5111-00', N'ROLL M/C Common', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (93, N'5111-01', N'Rough Cut', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (94, N'5111-02', N'Center', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (95, N'5111-03', N'ROLL M/C  CNC Late', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (96, N'5111-04', N'M/C Center (Ring roll)', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (97, N'5111-05', N'ROLL M/C Grinding', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (98, N'5111-06', N'Plan Cut', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (99, N'5111-07', N'Flower Cut', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (100, N'5111-08', N'Drilling', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (101, N'5111-09', N'Hand Finish', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (102, N'5111-10', N'ROLL M/C Packing', 16, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (106, N'81', N'Maintenance', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (24, N'8100', N'MT Common', NULL, 3)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (3, N'91', N'ADMIN', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (4, N'9100', N'Admin Common', NULL, 5)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (5, N'9110', N'Account', 1, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (6, N'9111', N'Purchase', 2, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (7, N'9112', N'Human Resource', 3, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (8, N'9113', N'Quality Assurance', 4, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (9, N'9114', N'Quality Control', 5, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (10, N'9115', N'Safety', 6, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (11, N'9116', N'Doc.Control', 7, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (12, N'9117', N'Sale', 8, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (13, N'9118', N'Planning', 9, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (14, N'9119', N'Store&Delivery', 10, NULL)
    INSERT [dbo].[GSS_HR_COSTCENTER] ([Cost_ID], [Cost_code], [Cost_name], [Dept_ID], [DeptGroup_ID]) VALUES (120, N'9120', N'R & D Engineering', 19, NULL)
    SET IDENTITY_INSERT [dbo].[GSS_HR_COSTCENTER] OFF
    SET IDENTITY_INSERT [dbo].[GSS_HR_COSTRELATION] ON 
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (1, N'02', N'01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (2, N'03', N'01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (3, N'91', N'02', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (4, N'9100', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (5, N'9110', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (6, N'9111', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (7, N'9112', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (8, N'9113', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (9, N'9114', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (10, N'9115', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (11, N'9116', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (12, N'9117', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (13, N'9118', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (14, N'9119', N'91', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (15, N'11', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (16, N'2100', N'21', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (17, N'2110', N'21', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (18, N'2111', N'21', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (19, N'2112', N'21', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (20, N'2113', N'21', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (21, N'5100', N'51', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (22, N'5110', N'51', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (23, N'5111', N'51', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (24, N'8100', N'81', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (121, N'2110-01', N'2110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (122, N'2110-01-0201', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (123, N'2110-01-0202', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (124, N'2110-01-0203', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (125, N'2110-01-0204', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (126, N'2110-01-0205', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (127, N'2110-01-0206', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (128, N'2110-01-0207', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (129, N'2110-01-0208', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (130, N'2110-01-0209', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (131, N'2111-0213-0301', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (132, N'2111-0213-0201', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (133, N'2111-0213-0202', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (134, N'2111-0212-0301', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (135, N'2111-0212-0201', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (136, N'2111-0211-0301', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (137, N'2111-0211-0201', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (42, N'2111-01', N'2110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (43, N'2111-0110', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (44, N'2111-0111', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (45, N'2111-0112', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (46, N'2111-0113', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (47, N'2111-0114', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (48, N'2111-02', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (49, N'2111-0210', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (50, N'2111-0211', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (51, N'2111-0212', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (52, N'2111-0213', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (53, N'2111-0214', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (54, N'2111-0215', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (55, N'2111-0216', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (56, N'2111-0217', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (57, N'2111-0218', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (58, N'2111-0219', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (59, N'2111-0220', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (60, N'2111-0221', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (61, N'2111-0222', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (62, N'2111-03', N'2111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (63, N'2112-00', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (64, N'2112-01', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (65, N'2112-0110', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (66, N'2112-02', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (67, N'2112-0210', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (68, N'2112-0211', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (69, N'2112-0212', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (70, N'2112-0213', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (71, N'2112-0214', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (72, N'2112-0215', N'2112', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (73, N'2113-00', N'2113', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (74, N'2113-01', N'2113', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (75, N'2113-02', N'2113', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (76, N'2113-03', N'2113', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (77, N'2113-04', N'2113', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (78, N'2113-05', N'2113', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (79, N'2113-06', N'2113', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (80, N'5110-00', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (81, N'5110-01', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (82, N'5110-02', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (83, N'5110-03', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (84, N'5110-04', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (85, N'5110-05', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (86, N'5110-06', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (87, N'5110-07', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (88, N'5110-08', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (89, N'5110-09', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (90, N'5110-10', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (91, N'5110-11', N'5110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (92, N'5111-00', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (93, N'5111-01', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (94, N'5111-02', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (95, N'5111-03', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (96, N'5111-04', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (97, N'5111-05', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (98, N'5111-06', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (99, N'5111-07', N'5111', NULL)
    GO
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (100, N'5111-08', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (101, N'5111-09', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (102, N'5111-10', N'5111', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (103, N'11', N'03', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (104, N'21', N'03', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (105, N'51', N'03', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (106, N'81', N'03', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (107, N'01', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (108, N'2110-00', N'2110', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (109, N'2110-01-0101', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (110, N'2110-02-0102', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (111, N'2110-03-0103', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (112, N'2110-04-0104', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (113, N'2110-05-0105', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (114, N'2110-06-0106', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (115, N'2110-07-0107', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (116, N'2110-08-0108', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (117, N'2110-09-0109', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (138, N'2111-0211-0202', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (139, N'2111-0211-0203', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (140, N'2111-0211-0204', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (141, N'2111-0210-0301', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (142, N'2111-0210-0201', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (143, N'2111-0210-0202', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (144, N'2111-0210-0203', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (145, N'2111-0214-0301', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (146, N'2111-01-0401', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (147, N'2111-01-0402', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (148, N'2111-01-0501', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (149, N'2111-01-0201', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (150, N'2111-01-0202', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (151, N'2111-0219-0901', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (152, N'2111-0219-0902', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (153, N'2111-0219-0903', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (154, N'2111-0219-0904', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (155, N'2111-0219-0905', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (156, N'2111-0219-0906', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (157, N'2111-0216-1101', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (158, N'2111-0216-1102', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (159, N'2111-0216-1103', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (160, N'2111-0216-1104', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (161, N'2111-0216-1105', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (162, N'2111-0216-1106', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (163, N'2111-0216-1107', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (164, N'2111-0216-1108', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (165, N'2111-0216-1109', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (166, N'2111-0216-1110', NULL, NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (118, N'2110-10-0110', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (119, N'2110-11-0111', N'2110-01', NULL)
    INSERT [dbo].[GSS_HR_COSTRELATION] ([Relation_ID], [Child_Code], [Parent_Code], [FLG]) VALUES (120, N'9120', N'91', NULL)
    SET IDENTITY_INSERT [dbo].[GSS_HR_COSTRELATION] OFF

    >> I want to sum every parent recursively to the top of parent <<
    The terms “parent” and “child” are part of network databases and NOT RDBMS. We have “weak entity” and “{strong entity” in our data models today.
    If you use the nested sets model, this hierarchical aggregation is easy. But your mindset is still in file systems, pointer chains and procedural language programming code. You also have no idea how ISO-11179 naming rules work. 
    Most of the data element names are garbage! Most of your code is garbage, even after we get over the fundamental design errors. 
    Think about how absurd “qty” as a data element name is in a schema. Quantity of what?? From logic (specifically the Law of Identity, the most fundamental law in mathematics) that “to be” (exist) is to be something in particular; so this has to be “<something
    in particular>_qty” to be valid. Your other data elemet names are also vague garbage. 
    We do NOT use flags in SQL; this is a predicate language like Assembly code. We do NOT set flags; we discover a current “state of being” with predicates. 
    Think about “GSS_Hr_Cost_Relation” as a name. Is there only one of them, as you have said?? Would also call a table of “Marriages” a “Man_Woman_Legal_Relations” ? NO! The relationship has a name of its own! 
    CAST(1 AS FLOAT) is better written AS a constant E1.0; but it is weird. why are you using FLOAT? Do you want rounding errors? Why do you write crap like “CAST(34.00 AS DECIMAL(16, 2)”  when an insertion of just 34.00 works better? Why do you write crap
    like “CAST(0x0000a3db00000000 AS DATETIME” instead of using ISO-8601 formats, DATE and DATETIME2(0) data types? 
    Then you have no idea what kind of attribute a “<something>_code” is and why it cannort ever be key. Go to any library and look at the Dewey DECIMAL Classification system. The hierarchy is in the encoding itself, NOT in some multiple levels of storage. 
    Why do you have more NULL-able columns than the loan systems of major automobile corporations? I can answer that! Your schema is a disaster that needs to be re-done. 
    Putting audit data into the table being audited is both stupid and illegal! And then to make it worse, “datecreated” should have been “creation_date” if the moron knew ISO-11179 rules. But it is still a crime; what happens to the audit data when the row is
    deleted or the table is dropped? Can a person with access to the data also have access to the audit trail? DOH! 
    The use of “NVARCHAR(50)” might be correct in places where the data actually is in Unicode varying strings. I think I have seen ~10 of them in 30 years of writing SQL. But everything does not qualify; most likely some moron using ACCESS or a ORM tool used this
    default because he is both stupid and lazy. Fire him; his ignorance is dangerous to the project. 
    Most ISO encodings are fixed length and between 9 and 16 characters with a regular expression for validation. Not all but most. 
    Finally, after all the decades of RDBMS, why do you use “mat_id INTEGER IDENTITY(1,1) NOT NULL”?? Why do you think that the insertion attempt count of one table is a valid logical attribute, much less a KEY? 
    You do not know how to write an INSERT UNTO statement! Look up the VALUES () clause and row constructions. 
    I have decades of my life invested in SQL and RDBMS. Reading code like this is painful. Can you please get a minimal education and correct this mess? I have been asked to write a book on bad SQL and this is classic illiterate programming! Almost nothing is
    right. 
    Sorry, but you wanted help and the best help is to stop you from doing more harm until you can learn how to do it properly. >> I want to sum every parent recursively to the top of parent <<
    The terms “parent” and “child” are part of network databases and NOT RDBMS. We have “weak entity” and “{strong entity” in our data models today.
    If you use the nested sets model, this hierarchical aggregation is easy. But your mindset is still in file systems, pointer chains and procedural language programming code. You also have no idea how ISO-11179 naming rules work. 
    Most of the data element names are garbage! Most of your code is garbage, even after we get over the fundamental design errors. 
    Think about how absurd “qty” as a data element name is in a schema. Quantity of what?? From logic (specifically the Law of Identity, the most fundamental law in mathematics) that “to be” (exist) is to be something in particular; so this has to be “<something
    in particular>_qty” to be valid. Your other data elemet names are also vague garbage. 
    We do NOT use flags in SQL; this is a predicate language like Assembly code. We do NOT set flags; we discover a current “state of being” with predicates. 
    Think about “GSS_Hr_Cost_Relation” as a name. Is there only one of them, as you have said?? Would also call a table of “Marriages” a “Man_Woman_Legal_Relations” ? NO! The relationship has a name of its own! 
    CAST(1 AS FLOAT) is better written AS a constant E1.0; but it is weird. why are you using FLOAT? Do you want rounding errors? Why do you write crap like “CAST(34.00 AS DECIMAL(16, 2)”  when an insertion of just 34.00 works better? Why do you write crap
    like “CAST(0x0000a3db00000000 AS DATETIME” instead of using ISO-8601 formats, DATE and DATETIME2(0) data types? 
    Then you have no idea what kind of attribute a “<something>_code” is and why it cannort ever be key. Go to any library and look at the Dewey DECIMAL Classification system. The hierarchy is in the encoding itself, NOT in some multiple levels of storage. 
    Why do you have more NULL-able columns than the loan systems of major automobile corporations? I can answer that! Your schema is a disaster that needs to be re-done. 
    Putting audit data into the table being audited is both stupid and illegal! And then to make it worse, “datecreated” should have been “creation_date” if the moron knew ISO-11179 rules. But it is still a crime; what happens to the audit data when the row is
    deleted or the table is dropped? Can a person with access to the data also have access to the audit trail? DOH! 
    The use of “NVARCHAR(50)” might be correct in places where the data actually is in Unicode varying strings. I think I have seen ~10 of them in 30 years of writing SQL. But everything does not qualify; most likely some moron using ACCESS or a ORM tool used this
    default because he is both stupid and lazy. Fire him; his ignorance is dangerous to the project. 
    Most ISO encodings are fixed length and between 9 and 16 characters with a regular expression for validation. Not all but most. 
    Finally, after all the decades of RDBMS, why do you use “mat_id INTEGER IDENTITY(1,1) NOT NULL”?? Why do you think that the insertion attempt count of one table is a valid logical attribute, much less a KEY? 
    You do not know how to write an INSERT UNTO statement! Look up the VALUES () clause and row constructions. 
    I have decades of my life invested in SQL and RDBMS. Reading code like this is painful. Can you please get a minimal education and correct this mess? I have been asked to write a book on bad SQL and this is classic illiterate programming! Almost nothing is
    right. 
    Sorry, but you wanted help and the best help is to stop you from doing more harm until you can learn how to do it properly. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • 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?

  • UpGrade failed 9.3.4294 (2005 SP3 PatchSet 9) to 10.50.1600.1.

    Hi, I've tried an UpGrade from 9.3.4294 (2005 SP3 PatchSet 9) to 10.50.1600.1. (SAP media ID 51039339)
    The setup failed by execution of 'sqlagent100_msdb_upgrade.sql' with error code 574.
    I found the following KB articele http://support.microsoft.com/kb/960781 and this blog http://blogs.msdn.com/b/psssql/archive/2008/09/10/upgrade-for-sql-server-2008-can-fail-if-you-have-renamed-the-sa-account.aspx.
    I could start the service and execute the proposed statement to my named instance as followes:
    ...Binnsqlservr.exe" -sSAPQPT -c -f -T 3608
    <-- message if sqlcmd is active:
    2011-05-20 16:13:46.88 spid51 Starting up database 'QPT'.
    2011-05-20 16:13:47.89 spid51 CHECKDB for database 'QPT' finished without e
    rrors on 2011-05-15 09:00:06.870 (local time). This is an informational message
    only; no user action is required.
    sqlcmd -S tpzsqp01SAPQPT -E -A -Q"alter login <sys-admin> with name = sa"
    <-- this gives no feedback to the console...
    After this I've used the Repair function of the SQL 2008 setup, but it failed on the same scipt 'sqlagent100_msdb_upgrade.sql'.
    I've also tried to change the sa password
    sqlcmd -S tpzsqp01SAPQPT -E -A -Q"ALTER LOGIN sa WITH PASS
    WORD = 'xxx' UNLOCK;"
    But I'm not able to connect to the server via TCP
    C:Windowssystem32>sqlcmd -U sa
    Password: HResult 0x274D, Level 16, State 1
    TCP Provider: No connection could be made because the target machine actively re
    fused it.
    Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establi
    shing a connection to the server. When connecting to SQL Server 2005, this failu
    re may be caused by the fact that under the default settings SQL Server does not
    allow remote connections..
    Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.
    At the moment I don't know what is wrong with the master db and why the setup can not connect with the sa account... we did not change this account in the past?! I've done the setup and this failed with the same error as described in http://support.microsoft.com/kb/960781. I've followed up this KB article but it did not solve the problem. The problem is still available.
    Error messages by setup are:
    Detail.txt
    2011-05-20 10:26:03 Slp: Error result: -2061893608
    2011-05-20 10:26:03 Slp: Result facility code: 1306
    2011-05-20 10:26:03 Slp: Result error code: 24
    SQLServer_ERRORLOG_2011-05-20T09.47.03.txt
    cript level upgrade for database 'master' failed because upgrade step 'sqlagent100_msdb_upgrade.sql' encountered error 574, state 0, severity 16. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.
    Detailed results:
    Feature: Database Engine Services
    Status: Failed: see logs for details
    MSI status: Passed
    Configuration status: Failed: see details below
    Configuration error code: 0x4BDAF9BA@1306@24
    Configuration error description: Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes.
    Configuration log: C:Program FilesMicrosoft SQL Server100Setup BootstrapLog20110520_164101Detail.txt
    Feature: SQL Server Replication
    Status: Failed: see logs for details
    MSI status: Passed
    Configuration status: Failed: see details below
    Configuration error code: 0x4BDAF9BA@1306@24
    Configuration error description: Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes.
    Configuration log: C:Program FilesMicrosoft SQL Server100Setup BootstrapLog20110520_164101Detail.txt
    Feature: Full-Text Search
    Status: Failed: see logs for details
    MSI status: Passed
    Configuration status: Failed: see details below
    Configuration error code: 0x4BDAF9BA@1306@24
    Configuration error description: Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes.
    Configuration log: C:Program FilesMicrosoft SQL Server100Setup BootstrapLog20110520_164101Detail.txt
    Edited by: René Schulz on May 24, 2011 9:23 AM

    for further ideas with trace flag -T3601; the upgrade script seems to have a problem with RECONFIGURE ??? :
    /* DMF Post-upgrade steps */
    -- >>> CTP5 -> CTP6 Upgrade
    -- Restoring previously saved data and converting TargetSets to ObjectSets
    IF (OBJECT_ID('dbo.dmf_upgrade', 'U') IS NOT NULL)
    BEGIN
    BEGIN TRANSACTION
    -- Restore policies
    SET IDENTITY_INSERT dbo.syspolicy_policies_internal ON
    INSERT dbo.syspolicy_policies_internal (policy_id,name,condition_id,root_condition_id,date_created,execution_mode,policy_category_id,schedule_uid,description,help_text,help_link,is_enabled,job_id,created_by,modified_by,date_modified)
    SELECT policy_id,name,condition_id,root_condition_id,date_created,execution_mode,policy_category_id,schedule_uid,description,help_text,help_link,is_enabled,job_id,created_by,modified_by,date_modified
    FROM msdb.dbo.tmp_syspolicy_policies_internal
    SET IDENTITY_INSERT dbo.syspolicy_policies_internal OFF
    -- Restore Health state
    SET IDENTITY_INSERT dbo.syspolicy_system_health_state_internal ON
    INSERT dbo.syspolicy_system_health_state_internal (health_state_id,policy_id,last_run_date,target_query_expression_with_id,target_query_expression,result)
    SELECT * FROM msdb.dbo.tmp_syspolicy_system_health_state_internal
    SET IDENTITY_INSERT dbo.syspolicy_system_health_state_internal OFF
    -- Restore Execution history
    SET IDENTITY_INSERT dbo.syspolicy_policy_execution_history_internal ON
    INSERT dbo.syspolicy_policy_execution_history_internal (history_id,policy_id,start_date,end_date,result,is_full_run,exception_message,exception)
    SELECT * FROM msdb.dbo.tmp_syspolicy_policy_execution_history_internal
    SET IDENTITY_INSERT dbo.syspolicy_policy_execution_history_internal OFF
    SET IDENTITY_INSERT dbo.syspolicy_policy_execution_history_details_internal ON
    INSERT dbo.syspolicy_policy_execution_history_details_internal (detail_id,history_id,target_query_expression,target_query...
    2011-05-23 14:03:53.29 spid7s Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
    2011-05-23 14:03:53.29 spid7s Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
    2011-05-23 14:03:53.30 spid7s Error: 574, Severity: 16, State: 0.
    2011-05-23 14:03:53.30 spid7s CONFIG statement cannot be used inside a user transaction.
    2011-05-23 14:03:53.30 spid7s Error: 912, Severity: 21, State: 2.

Maybe you are looking for

  • HT202213 can i share with different apple id

    I have a macbook pro.  My wife has an Imac.  We both have home sharing turned on...and she can see my device in itunes...but I cannot see her device at all.  Any suggestions??

  • Iphone calendar displaying wrong times in day/week view

    I work a lot of night shifts and consequently I input a lot of night shifts to my iphone calendar. They usually work. However, in a couple of weekends time I have some nights which I have input as starting on 30th march 20.45 ending 31st march 08.00,

  • Why can I not make comments on pdf files?

    OK this has been driving me nuts for a couple years now.  I used to have an earlier versison of Acrobat Reader (5.0 maybe?) where I could freely highlight and make comments throughout the document--very easy and straightforward.  When I got a new com

  • IDoc Flat File Needed

    Hi Experts.     I need the Idoc flat file for Delfor01(delivery schedule). Advance Thanks.

  • How to delet music on ipod

    How to delet music