By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

hot to insert cvs file in sql

P: 11
hi
i m trying to insert .csv file in ms sqlserver but its not working


my cvs file data formate below is


Expand|Select|Wrap|Line Numbers
  1. "12.204.8.120","12.204.8.151","214698104","214698135","VI","Virgin Islands, U.S."
  2. "12.204.8.152","12.204.8.159","214698136","214698143","PR","Puerto 
  3.  
  4. Rico"
  5. "12.204.8.160","12.204.8.175","214698144","214698159","VI","Virgin Islands, U.S."
  6. "12.204.8.176","12.204.8.183","214698160","214698167","PR","Puerto Rico"
  7. "12.204.8.184","12.204.8.191","214698168","214698175","VI","Virgin Islands, 
  8.  
  9. U.S."
  10. "12.204.8.192","12.204.8.255","214698176","214698239","PR","Puerto Rico"
  11. "12.204.9.0","12.204.9.79","214698240","214698319","VI","Virgin 
  12.  
  13. Islands, U.S."
  14. "12.204.9.80","12.204.9.127","214698320","214698367","PR","Puerto Rico"
  15. "12.204.9.128","12.204.9.135","214698368","214698375","VI","Virgin Islands, U.S."
  16. "12.204.9.136","12.204.9.143","214698376","214698383","US","United 
  17.  
  18. States"
  19. "12.204.9.144","12.204.10.143","214698384","214698639","PR","Puerto Rico"
  20. "12.204.10.144","12.204.10.159","214698640","214698655","VI","Virgin 
  21.  
  22. Islands, U.S."
  23. "12.204.10.160","12.204.12.223","214698656","214699231","PR","Puerto Rico"
i m using this code


Expand|Select|Wrap|Line Numbers
  1. use DBGMTEST
  2. Go
  3.  Create table csvtest
  4. ( begin_addr char(50) not null,
  5. end_addr char(50) not null,
  6. begin_num varchar(50) not null,
  7. end_num varchar(50) not null,
  8. code char(20) not null,
  9. country varchar(max) not null,
  10. )
  11. Go
  12. Bulk Insert csvtest
  13. from 'C:\GM\GeoIP.csv'
  14. with
  15. (
  16.  
  17. Fieldterminator = '","',
  18. ROWTERMINATOR = '\r\n'
  19. )
  20. Go
  21. select * from csvtest
  22. Go
  23. Drop table csvtest
  24.  
  25. Go
this code works not giviing any error but the quatation marks "" does't remove and ROWTERMINATOR does't work.


its show all data of csv file in one row.the last field (country) of my table shows all data

pls help me
May 17 '10 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
Use a format file.Here, read this...

Happy Coding!!!

~~ CK
May 17 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.