sqlcmd script with spaces in filename

SuperNES picture SuperNES · Jan 18, 2011 · Viewed 20.5k times · Source

I have a simple SQLCMD script that includes some lines like this:

/* Load data into Exampletable */
BULK INSERT dbo.Example
    /* NOTE: I've tried single AND double quotes here. */
    FROM "C:\Example Filepath\test.csv"
    WITH 
    (
            /* skip the first row containing column names */
            FIRSTROW = 2,
            /* specify how fields are separated */
            FIELDTERMINATOR = '|',
            /* specify how lines end */
            ROWTERMINATOR = '\n' 
    )

When I run it on the command line, I get an error like this:

Sqlcmd: 'C:\Example': Invalid filename.

I think that having a space in the path is causing the path to be cut off, but I can't figure out a syntax that works. Does anybody have any experience with this?

Answer

devio picture devio · Jan 18, 2011

The error message sounds like sqlcmd cannot find the .sql file.

Try sqlcmd "c:\example filepath\test.sql" from the command prompt.

Strings are quoted with single quotes in TSQL, with double quotes in cmd.