Solved

Import form Excel in SQL Server 2012.

Posted on 2014-10-31
7
84 Views
Last Modified: 2014-11-17
Hello,

I have an excel document with one tab called Measurements.  The tab has many columns but i am only interested in one called PersonKod

I want to import this column into a new table in the database.  I have tried to write my own query but i cant get the syntax correct.

What would be the correct Insert statement to just read this one column?  Do i need to create the table before hand, or can i do that in the next step?
0
Comment
Question by:soozh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40415215
Do you have to use query for this? Can use import import data option?

Here is step by step: http://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/

but if you need it from query here are some good examples http://support.microsoft.com/kb/321686
0
 

Author Comment

by:soozh
ID: 40415239
Hello,

Yes i need to use a query because i only want one column.  There are some columns that fail during the import.

On the microsoft page it says:

Import vs. Append

The sample SQL statements that are used in this article demonstrate Create Table queries that import Excel data into a new SQL Server table by using the SELECT...INTO...FROM syntax. You can convert these statements to Append queries by using the INSERT INTO...SELECT...FROM syntax while you continue to reference the source and destination objects as shown in these code samples.

Its just that syntax i am having trouble with!  And my other question relating to the destination table.  Will the import tool create it from my query?
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40415247
You can specify the columns you need in the Import tool...  

can you post your syntax?

If you use select .. into .  table will be create otherwise you need to prepare the table..
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 9

Expert Comment

by:selva_kongu
ID: 40415323
Use the sql server data import export wizard
import wizand select the source as Microsoft excel and select the excel file
source filethen select the destination sql server and db
destination serverfrom next screen select sheet and click the edit mapping and select column mappings for source and destination
edit mappingsfinish with run immediately option.
0
 

Author Comment

by:soozh
ID: 40415355
Hello,

Sevla kongu - thanks for the instructions - i can already import that way... i am trying to write my own query rather than let the import do it.

As i wrote :
I have an excel document with one tab called Measurements.  The tab has many columns but i am only interested in one called PersonKod

so maybe it should be something like ?

insert into Newtable (personkod)
  select personkod from Measurements$
0
 
LVL 2

Expert Comment

by:Pratik Makwana
ID: 40415426
Please try by this excel...
Book1.xlsx
0
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 500 total points
ID: 40415545
Try like this:

for Excel 2007 and up

SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
  'Excel 12.0;Database=C:\excel-sql-server.xlsx', 'Select PersonKod from  [Measurements$]')

for Excel 2003 

SELECT * INTO NEW_TABLE_NAME FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test\xltest.xls', 'SELECT PersonKod FROM [Measurements$]')

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question