Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 T-SQL: Import Excel List into SQL Server Table

Author  Topic 

landau66
Yak Posting Veteran

61 Posts

Posted - 2008-01-08 : 08:42:02
Hi everyone!

I asked a similar question like this yesterday but i didnt work the way I wanted it to work. So I will ask in a diffrent way:

I have an Excel list which i want to import into a table in my SQL Server 2005. The ServerTable has one more column (for the the primary key which is created automatically) than the ExcelList. How can i import the ExcelList in a way so that I the first column of my ServerTable is not filled by a column of my ExcelList??

That is how far I came:

select *
into SQLServerTable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')


many thanks and greetings from austria

landau

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-08 : 08:46:58
If you have already a table, then

Insert into table(columns) --omit the primary key colum
select * from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

landau66
Yak Posting Veteran

61 Posts

Posted - 2008-01-08 : 09:18:58
How do i have to name the Columns?? Do i use the given column letters (A,B,C,....) ??


Insert into table(COLUMNS) --omit the primary key colum
select * from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')

Thanks, Landau
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-08 : 09:31:11
Do you want to create a new table or insert records to the existing table?
If you want to insert to an existing table, then specify the columns of that table and exclude the primary key column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -