Sample code for 30+ languages & platforms
SQL Server

CSV - Convert Comma to Semicolon Separators

See more CSV Examples

Load a CSV using comma delimiters and convert to a CSV using semicolon delimiters.

Note: This example requires Chilkat v9.5.0.89 or greater.

Chilkat SQL Server Downloads

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @csv int
    EXEC @hr = sp_OACreate 'Chilkat.Csv', @csv OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @csv, 'LoadFile2', @success OUT, 'qa_data/csv/csv_wit_comma_separators.csv', 'utf-8'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @csv, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @csv
        RETURN
      END

    --  Note: Prior to Chilkat v9.5.0.89, setting the Delimiter property did not modify the already-existing
    --  rows in the CSV.  Updating the Delimiter property in Chilkat v9.5.0.89 or greater will cause
    --  all rows to be updated with the new delimiter.
    EXEC sp_OASetProperty @csv, 'Delimiter', ';'

    EXEC sp_OAMethod @csv, 'SaveToString', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @csv


END
GO