0

I am trying to import data from Excel to SQL Server tables but I am getting this error. Can you please suggest how to avoid these.

Mappings

Import data Errors

Aruna Raghunam
  • 903
  • 7
  • 22
  • 43

2 Answers2

1

This is probably caused by the ACYR_ISN column beeing set to identity.

See this post for how to resolve the issue: https://stackoverflow.com/a/20953512/2280148

Community
  • 1
  • 1
JohannesGbg
  • 101
  • 1
  • 4
  • 1
    Taglines aren't allowed in posts here, particularly ones that advertise products, so I've removed that portion of your answer. You're welcome to place this information in your profile, if you'd like. – Brad Larson Apr 20 '16 at 02:05
1

You can import excel file into MSSQL database by using T-SQL.

DECLARE @strQuery AS VARCHAR(600),
        @strFilePath as VARCHAR(200),
        @TableName AS VARCHAR(50),
        @EmpCode varchar(8), 
        @Name varchar(50)

Declare @DataTable as table
    (
       EmpCode varchar(8), 
       Name varchar(50)
     )


SET @strFilePath='\\Path\Excel.xlsx'
SET @TableName='Sheet1'

SET @strQuery='select * from openrowset('
    SET @strQuery=@strQuery+'''Microsoft.ACE.OLEDB.12.0'''+','
    set @strQuery=@strQuery+ '''Excel 12.0;Database='+@strFilePath+''''+','
    SET @strQuery=@strQuery+'''select * from ['+@TableName+'$]'''+')'

insert into @DataTable 
EXECUTE(@strQuery)


declare curStaff cursor for
select * from @DataTable
open curStaff
fetch from curStaff into @EmpCode, @Name
while @@FETCH_STATUS =0
    begin
      //Do your work here by using data
    fetch from curStaff into  @EmpCode, @Name 
end
close curStaff
deallocate curStaff
Pritam Jyoti Ray
  • 320
  • 1
  • 8
  • 12