15

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?

SuperNES
  • 2,760
  • 9
  • 37
  • 49

2 Answers2

13

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.

devio
  • 36,858
  • 7
  • 80
  • 143
1

Surround the path with single quotes like:

'C:\Example Filepath\test.csv'
nan
  • 19,595
  • 7
  • 48
  • 80
  • @SuperNES I have just tested it with single quotes and works fine. Maybe your file does not exists or you do not have permissions. Check also here: http://msdn.microsoft.com/en-us/library/ms188365(v=sql.90).aspx – nan Jan 18 '11 at 16:44