C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » SQL »

Transfer of Data from CSV file to Sql Server table


Posted Date: 21 May 2009    Resource Type: Code Snippets    Category: SQL
Author: Rajesh.DharmakkanMember Level: Gold    
Rating: 1 out of 5Points: 8



Transfer of Data from CSV file to Sql Server table.


The CSV stands for Comma Separated value, Basically the CSV file would be the text file. The values which are separated by comma are stored in this file. The Values form CSV file can be transferred to the SQL server table.
Example :
Create one table for testing.

Create Table Teams (id bigint, name varchar(100), NoofMatches numeric(10,0), TotalPoints Numeric(10,0)

Now the table named Teams are created.
Create the CSV file with the values. Consider the CSV file name was “Teams.TXT”.
1,India,150,250
2,Australia,170,300
3,England,124,200
The above values are in the text file. Here is the script with get the values form the text file and insert into the sql table.

BULK INSERT Teams
--- This is the Table name which you needs to insert value
FROM ‘c:\Teams.txt’
---- This is the TXT file name which has the CSV values.
WITH
(
FIELDTERMINATOR = ‘,’,
---- This is for specify the separator value. The values are separated by the above mentioned value. The field values should be separated by the value “,”.
ROWTERMINATOR = ‘\n’
----- This is for specify the Row end separator. By default “\n” is the row terminator.
)
GO


After run the above code the values which available in the csv file would be transferred to the table “Teams”. The bulk insert is the statement which gets the values from the CSV files.
For confirm the data transfer check with select Query.

Select * from Teams




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
CSV file import  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to use TRY CATCH block in Stored Procedure?
Previous Resource: Create XML FROM SQL Server Using Explicit
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use