Solved

Import form Excel in SQL Server 2012.

Posted on 2014-10-31
7
82 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
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
insert into table 8 22
What is the proper way to use for criteria in left join? 7 25
SSIS with VPN COnnection 2 70
create an aggregate function 9 31
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now