hot to insert cvs file in sql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gm000
    New Member
    • Nov 2009
    • 11

    hot to insert cvs file in sql

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


    my cvs file data formate below is


    Code:
    "12.204.8.120","12.204.8.151","214698104","214698135","VI","Virgin Islands, U.S."
    "12.204.8.152","12.204.8.159","214698136","214698143","PR","Puerto 
    
    Rico"
    "12.204.8.160","12.204.8.175","214698144","214698159","VI","Virgin Islands, U.S."
    "12.204.8.176","12.204.8.183","214698160","214698167","PR","Puerto Rico"
    "12.204.8.184","12.204.8.191","214698168","214698175","VI","Virgin Islands, 
    
    U.S."
    "12.204.8.192","12.204.8.255","214698176","214698239","PR","Puerto Rico"
    "12.204.9.0","12.204.9.79","214698240","214698319","VI","Virgin 
    
    Islands, U.S."
    "12.204.9.80","12.204.9.127","214698320","214698367","PR","Puerto Rico"
    "12.204.9.128","12.204.9.135","214698368","214698375","VI","Virgin Islands, U.S."
    "12.204.9.136","12.204.9.143","214698376","214698383","US","United 
    
    States"
    "12.204.9.144","12.204.10.143","214698384","214698639","PR","Puerto Rico"
    "12.204.10.144","12.204.10.159","214698640","214698655","VI","Virgin 
    
    Islands, U.S."
    "12.204.10.160","12.204.12.223","214698656","214699231","PR","Puerto Rico"
    i m using this code


    Code:
    use DBGMTEST
    Go
     Create table csvtest
    ( begin_addr char(50) not null,
    end_addr char(50) not null,
    begin_num varchar(50) not null,
    end_num varchar(50) not null,
    code char(20) not null,
    country varchar(max) not null,
    )
    Go
    Bulk Insert csvtest
    from 'C:\GM\GeoIP.csv'
    with
    (
    
    Fieldterminator = '","',
    ROWTERMINATOR = '\r\n'
    )
    Go
    select * from csvtest
    Go
    Drop table csvtest
    
    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
    Last edited by Frinavale; May 18 '10, 07:37 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Use a format file.Here, read this...

    Happy Coding!!!

    ~~ CK

    Comment

    Working...