Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Bulk Insert

Bulk Insert

Scheduled Pinned Locked Moved Database
database
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mhiny
    wrote on last edited by
    #1

    Hi, I have a data file which consists of data as below, Header xx|yy|zz aa|bb|cc Footer While iam inserting into table using bulk insert, this pipe(|) is also getting inserted into the table, here is my query iam using to insert the data using bulk insert. BULK Insert #TmpStList FROM 'D:\PSC07\HRDATA\HR2SSTS_TRAINING.TXT' WITH (FirstRow=1,LastRow= 3,DATAFILETYPE='char',FIELDTERMINATOR = '|', ROWTERMINATOR = '\n',keepnulls) I want result like this fields1 2 3 xx yy zz aa bb cc but i got this fileds1 2 3 Headerxx yy zz aa bb cc I don't want to insert (|) into Header .

    W 1 Reply Last reply
    0
    • M Mhiny

      Hi, I have a data file which consists of data as below, Header xx|yy|zz aa|bb|cc Footer While iam inserting into table using bulk insert, this pipe(|) is also getting inserted into the table, here is my query iam using to insert the data using bulk insert. BULK Insert #TmpStList FROM 'D:\PSC07\HRDATA\HR2SSTS_TRAINING.TXT' WITH (FirstRow=1,LastRow= 3,DATAFILETYPE='char',FIELDTERMINATOR = '|', ROWTERMINATOR = '\n',keepnulls) I want result like this fields1 2 3 xx yy zz aa bb cc but i got this fileds1 2 3 Headerxx yy zz aa bb cc I don't want to insert (|) into Header .

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Your header row should have as many columns as data rows. So you should modify your data to:

      Header||
      xx|yy|zz
      aa|bb|cc
      Footer||

      Although you can start from second row using FirstRow=2, note that: The FIRSTROW attribute is not intended to skip column headers. Skipping headers is not supported by the BULK INSERT statement. When skipping rows, the SQL Server Database Engine looks only at the field terminators, and does not validate the data in the fields of skipped rows.

      The need to optimize rises from a bad design. My articles[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups