Solved

csv file to sql server

Posted on 2011-09-06
6
233 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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