MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 8th, 2004, 07:07 AM
rogerfleming rogerfleming is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Harrow, NW London
Posts: 1 rogerfleming User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SQL Bulk Insert or BCP

Hi,

Does anyone know if it is possible when using SQL Bulk Insert or BCP will allow for a variable number of columns in the input csv file? Or is it a requirement for these two commands to have a fixed number of cols in the input file?

I'm using Bulk Insert with fieldterminator = '","' and rowterminator = '\n' for the delimited csv file, but my input file does not have a fixed number of cols, and is not padded out with the appropiate number of empty ",".

Is there a way around this?

Roger

Reply With Quote
  #2  
Old December 15th, 2004, 08:57 AM
kalbzayn kalbzayn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 2 kalbzayn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm not sure if you can have a variable number of fields in a csv file.

I'd probably just write something that would add the delimeter however many times the line needed in order to make it importable.

Then the bulk insert would work.

Reply With Quote
  #3  
Old December 17th, 2004, 07:19 PM
Aforsythe Aforsythe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 104 Aforsythe User rank is Private First Class (20 - 50 Reputation Level)Aforsythe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 22 h 8 m 10 sec
Reputation Power: 4
Both applications expect there to be the same number of columns in each row, even if you have a row of ,,,,,,,,,,,,,,,,,,,,,,,'s each of the empties is considered a NULL value.

Here is a quick and dirty fix:

Open the delimited file in Excel.
File - Save As
CSV File
Click YES (you want to lose any features that may not be compatible with CSV etc...)
Find the file
Rename it to .txt
Open it in Notepad
Make sure it has the newly added commas.

On Problem, your row delimiter is "," instead of just ,

Use DTS, and set Text Qualifier = "
Delimiter = ,
Rowterminator <CR><LF>

All 3 of those should be set by default.

Not sure about BULK INSERT, but I beleive BCP will allow a Text Qualifier as well, so you could just use your commas as delimeters instead of ",".

Let me know if you are still having issues I do this alot.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SQL Bulk Insert or BCP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT