April 3, 2015 at 7:40 am
Hi,
Someone was telling me that they had a text file that was both comma and piped delimited and that they used BCP to import it.
While they did not remember the exact details, they said that first it converted it to XML and then used bcp to import it.
Can someone explain how this is done; I cannot find anything on the web about it.
Thank you
April 3, 2015 at 11:59 pm
itmasterw 60042 (4/3/2015)
Hi,Someone was telling me that they had a text file that was both comma and piped delimited and that they used BCP to import it.
While they did not remember the exact details, they said that first it converted it to XML and then used bcp to import it.
Can someone explain how this is done; I cannot find anything on the web about it.
Thank you
Looks to me that some external tool must have been used for the text to xml conversion, don't have a recollection of such tool within the SQL Server stack.
😎
On the problem of importing multi-delimiter files, normally the delimiters are hierarchical, that is there is a precedence i.e. in this case it could be the comma as the higher level and pipe as the lower.
Input String ---> "ABC,DEF,GHI,J|K|L"
| | | | | |
| | | | | |
| | | | | |
(1) +--------------+ | | | | | |
,----+-| Header Table | | | | | | |
| +--------------+ | | | | | |
| | Column 1 |<------------' | | | | |
| +--------------+ | | | | |
| | Column 2 |<----------------' | | | |
| +--------------+ | | | |
| | Column 3 |<--------------------' | | |
| +--------------+ | | |
| | | |
| | | |
| (0-n)+--------------+ | | |
'----0<| Detail Table | | | |
+--------------+ | | |
| Column 1 |<-----------------------' | |
+--------------+ | |
| Column 2 |<-------------------------' |
+--------------+ |
| Column 3 |<---------------------------'
+--------------+
Importing this type of files is straight forward using a staging environment where the data is loaded using the highest level delimiter and then the appropriate columns are split on the lower level delimiters in the right order.
April 4, 2015 at 8:26 pm
itmasterw 60042 (4/3/2015)
Hi,Someone was telling me that they had a text file that was both comma and piped delimited and that they used BCP to import it.
While they did not remember the exact details, they said that first it converted it to XML and then used bcp to import it.
Can someone explain how this is done; I cannot find anything on the web about it.
Thank you
There's no need to jump through all those hoops if the delimiters are solid. Just create a BCP format file and you're done. It only takes a couple of minutes to create such a thing.
It would be helpful to know more about the file you're trying to import because there are a couple of "gotchas" with BCP. For example, the header row must have exactly the same delimiters as the body rows in order to successfully be able to skip the header rows.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply