Solved

csv file to sql server

Posted on 2011-09-06
6
235 Views
Last Modified: 2012-05-12
I want to migrate all the data from a CSV file to a new table in SQL.  However, I want to migrate only the records that are new.  There is an ID column that is unique to each record in my CSV file.  How do I import my data from CSV to SQL each time?
0
Comment
Question by:al4629740
[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
6 Comments
 
LVL 3

Expert Comment

by:liranp1
ID: 36493520
hi

i don't know much about DB's but from what i know you need to transfer the CSV to XML and then import the XML to SQL DB.
0
 

Author Comment

by:al4629740
ID: 36493550
how do I transfer it to xml?
0
 
LVL 6

Accepted Solution

by:
kswathi earned 250 total points
ID: 36493556
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 3

Expert Comment

by:JHolycloud
ID: 36493621
Here is the simplest idea :
  insert all your data from CSV file into temp table, from that temp table you could select the data which match your terms than insert them into your real table.
0
 
LVL 9

Assisted Solution

by:mimran18
mimran18 earned 250 total points
ID: 36493640
Here is the sample
csvtest.txt
Drop TABLE CSVTest
Go
CREATE TABLE CSVTest
(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO
Drop TABLE CSVtemp
Go
CREATE TABLE CSVtemp
(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO
BULK
INSERT CSVtemp
FROM 'c:\csvtest.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the existing data of the table and insert new records.
Insert into CSVTest SELECT *
FROM CSVtemp Where [ID] Not In (Select [ID] from CSVTest)
GO
--Select the main table.
SELECT *
FROM CSVTest
GO

Open in new window

0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 36494959
OK Create SSIS Package and use the Look for Check ID is available in Destination if not then insert else do nothing.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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