Solved

csv file to sql server

Posted on 2011-09-06
6
229 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
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Copy Database Wizard 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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

861 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

22 Experts available now in Live!

Get 1:1 Help Now