SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Converting delimiter


Converting delimiter

Author
Message
EMtwo
EMtwo
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2754 Visits: 513
Is there a way to change a comma delimited file to pipe delimited using a script?

Thanks.
frederico_fonseca
frederico_fonseca
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9869 Visits: 5410
yes assuming that the file is a correctly formed delimited file

read file using old delimiter - split columns - write to new file using new delimiter.

dead easy to do in Powershell - a bit more work in T-SQL

but I think more details of what you are trying to do are required
EMtwo
EMtwo
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2754 Visits: 513
I have been having trouble loading my comma delimited .csv file using Bulk Insert - commas in the data are being read as an end of a field and it's affecting the quality of the data - I have input of some fields that contain commas but not the end of the field. As a result, I have to manually remove all of the commas or change the delimiter to a pipe... what I want to do is automate this process and so I'm looking for a script that can convert the commas to pipe ...
frederico_fonseca
frederico_fonseca
SSCrazy Eights
SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)SSCrazy Eights (9.9K reputation)

Group: General Forum Members
Points: 9869 Visits: 5410
Was correct in assuming that what you asking for was not really the real requirement.

Changing the delimiter alone is not the solution if you have to parse the file before using bulk insert - better one of the following solutions

Assuming that the file is properly formatted as a CSV you can try the scriipt on this link http://bradsruminations.blogspot.com/2011/01/so-you-want-to-read-csv-files-huh.html

another options, and possibly better is to use powershell to read the file and load directly to the database - not always feasible but more functionality.
there are a few around - you can use Chrissy LeMaire one https://blog.netnerds.net/2015/09/import-csvtosql-super-fast-csv-to-sql-server-import-powershell-module/ or adapt it but the bulk of how to is there.
EMtwo
EMtwo
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2754 Visits: 513
Thank you very much; looking into it now. I will update you...
EMtwo
EMtwo
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2754 Visits: 513
Do you know if this issue persists across all SQL server versions or has it been fixed in any of the newer versions?
Ryan Besko
Ryan Besko
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1033 Visits: 4403
EMtwo - Thursday, November 8, 2018 11:28 AM
Do you know if this issue persists across all SQL server versions or has it been fixed in any of the newer versions?


It's not an issue with SQL Server. It's an issue with a malformed .csv file. If the field contents where enclosed in quotes, such as "some,value","another,value", then there are not problems with commas in the middle of a field. Any time a file is read by any system your file would be a problem.
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)SSC Guru (395K reputation)

Group: General Forum Members
Points: 395416 Visits: 43155
Read this article: http://www.sqlservercentral.com/articles/SQL+Server+2012/106903/

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search