Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:27:12+00:00 2026-05-31T04:27:12+00:00

i’m having problem insert record to a particular table regarding identity. But SQL always

  • 0

i’m having problem insert record to a particular table regarding identity. But SQL always tell to me that I need to turn on identity_insert but I already set identity column for that table so that i’m sure it will not produce multiple id. By the way my table has records already. Here’s my code

declare @empid int
declare @trans_name varchar(max) = 'Append'
declare @lname varchar(max)
declare @fname varchar(max)
declare @mname varchar(max)
declare @emp_id varchar(max)
declare @gender varchar(max)
declare @bday datetime
declare @allowance numeric(18,2)
declare @emp_sysid numeric(18,0)
declare @datehired datetime
declare @status varchar(max)
declare @positionid numeric(18,0)

declare cc_cur cursor for
    select emps.LNAME, emps.MNAME, emps.FNAME, emps.EMP_ID,
    emps.GENDER, emps.BDAY, emps.ALLOWANCE, emps.SYSID, 
    emps.DATE_HIRED, emps.[STATUS], emps.POSITION_SYSID
    from SPADA.dbo.M_EMPLOYEE emps
        where emps.SYSID not in (select ISNULL(B.SPADAEmpID, 0) from SPADA_FIS.dbo.HRIS_Employees B
                                inner join SPADA_FIS.dbo.HRIS_EmployeeStatus C
                                    on C.EmployeeID = B.EmployeeID where C.IsCurrent = 1)

open cc_cur
fetch next from cc_cur
into @lname, @mname, @fname, @emp_id, 
     @gender, @bday, @allowance, @emp_sysid, 
     @datehired, @status, @positionid

begin tran @trans_name
    while @@FETCH_STATUS = 0
    begin
        insert into SPADA_FIS.dbo.HRIS_Employees
        (LastName, MiddleName, FirstName, OtherName,
        Gender, BirthDate, Allowance)
        values
        (@lname, @mname, @fname, @emp_id,
        @gender, @bday, @allowance)

        set @empid = SCOPE_IDENTITY()

        insert into SPADA_FIS.dbo.HRIS_EmployeeStatus
        (EmployeeID, EmploymentTypeID, DepartmentID, EmploymentTenureID,
        Remarks, DateHired, JobOrganizationID, EmployeeStatusID, IsCurrent,
        PayFrequencyID, TaxExemptionStatus)
        values
        (@empid, 1, 6, (select htet.EmploymentTenureID 
                                from SPADA_FIS.dbo.HRIS_tblEmploymentTenures htet
                                    where htet.Tenure = @status),
        'Migrated Data', @datehired, (select htjo.JobOrganizationID from SPADA_FIS.dbo.HRIS_tblJobOrganizations htjo
                                            where htjo.Position = (select pos.POSITION from SPADA.dbo.M_POSITION pos
                                                where pos.SYSID = @positionid) or htjo.Position = 
                                                    (select pos2.[DESCRIPTION] from SPADA.dbo.M_POSITION pos2
                                                        where pos2.SYSID = @positionid)),
        1, 1, 2, 2)
        fetch next from cc_cur
        into @lname, @mname, @fname, @emp_id, 
             @gender, @bday, @allowance, @emp_sysid, 
             @datehired, @status, @positionid
    end
    close cc_cur
    deallocate cc_cur
if @@ERROR <> 0
rollback tran @trans_name
commit tran @trans_name

If i set identity_insert to on.. the identity column only produces value of 1.

This is the structure of my table

USE [SPADA_FIS]
GO

/****** Object:  Table [dbo].[HRIS_EmployeeStatus]    Script Date: 03/07/2012 17:13:03 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[HRIS_EmployeeStatus](
    [EmployeeStatusID] [int] IDENTITY(1,1) NOT NULL,
    [EmployeeID] [int] NULL,
    [EmploymentTypeID] [int] NULL,
    [DepartmentID] [int] NULL,
    [EmploymentTenureID] [int] NULL,
    [Remarks] [varchar](max) NULL,
    [DateHired] [datetime] NULL,
    [JobOrganizationID] [int] NULL,
    [SectionID] [int] NULL,
    [EmploymentStatusID] [int] NULL,
    [IsCurrent] [bit] NULL,
    [StartDate] [datetime] NULL,
    [IsUnionMember] [bit] NULL,
    [EndDate] [datetime] NULL,
    [PayFrequencyID] [int] NULL,
    [TaxExemptionStatus] [bigint] NULL,
    [IDNumber] [varchar](50) NULL,
    [BiometricNumber] [varchar](50) NULL,
    [BankAccountNumber] [varchar](50) NULL,
    [CreatedBy_UserID] [int] NULL,
    [CreatedDate] [datetime] NULL,
    [UpdatedBy_UserID] [int] NULL,
    [UpdatedDate] [datetime] NULL,
 CONSTRAINT [PK_HRIS_EmployeeStatus] PRIMARY KEY CLUSTERED 
(
    [EmployeeStatusID] 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

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_EmployeeID]  DEFAULT ((0)) FOR [EmployeeID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_EmploymentTypeID]  DEFAULT ((0)) FOR [EmploymentTypeID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_DepartmentID]  DEFAULT ((0)) FOR [DepartmentID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_EmploymentTenureID]  DEFAULT ((0)) FOR [EmploymentTenureID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_DateHired]  DEFAULT (getdate()) FOR [DateHired]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_JobOrganizationID]  DEFAULT ((0)) FOR [JobOrganizationID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_SectionID]  DEFAULT ((0)) FOR [SectionID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_EmploymentStatusID]  DEFAULT ((0)) FOR [EmploymentStatusID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_IsCurrent]  DEFAULT ((1)) FOR [IsCurrent]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_StartDate]  DEFAULT (getdate()) FOR [StartDate]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_IsUnionMember]  DEFAULT ((0)) FOR [IsUnionMember]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_EndDate]  DEFAULT (getdate()) FOR [EndDate]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_PayFrequencyID]  DEFAULT ((0)) FOR [PayFrequencyID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_TaxExemptionStatus]  DEFAULT ((0)) FOR [TaxExemptionStatus]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_CreatedBy_UserID]  DEFAULT ((0)) FOR [CreatedBy_UserID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_CreatedDate]  DEFAULT (getdate()) FOR [CreatedDate]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_UpdatedBy_UserID]  DEFAULT ((0)) FOR [UpdatedBy_UserID]
GO

ALTER TABLE [dbo].[HRIS_EmployeeStatus] ADD  CONSTRAINT [DF_HRIS_EmployeeStatus_UpdatedDate]  DEFAULT (getdate()) FOR [UpdatedDate]
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:27:14+00:00Added an answer on May 31, 2026 at 4:27 am

    That’s your problem: you have:

    CREATE TABLE [dbo].[HRIS_EmployeeStatus](
        [EmployeeStatusID] [int] IDENTITY(1,1) NOT NULL,
    

    and in your INSERT statement, you are trying to insert something into that column:

    insert into SPADA_FIS.dbo.HRIS_EmployeeStatus
            (EmployeeID, EmploymentTypeID, DepartmentID, EmploymentTenureID,
            Remarks, DateHired, JobOrganizationID, EmployeeStatusID, IsCurrent,
                                                   *****************
            PayFrequencyID, TaxExemptionStatus)
    

    Don’t do that ! The IDENTITY column will be handled by SQL Server itself. Just remove that column from the INSERT statement (and the value from the VALUES collection) and you should be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.