?
Solved

csv file to sql server

Posted on 2011-09-06
6
Medium Priority
?
241 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 1000 total points
ID: 36493556
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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 1000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

765 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