Brett, really, I'm trying to love bcp. However, it's a challenging relationship due to a terrible lack of communication. He just won't open up and talk to me. All this stonewalling is making me insecure and I may have to return to previous relationships. But I'd really like to work it out...
Here's what I've got:
Code:
-- This Works
BULK INSERT MyDatabase..MyView FROM 'MyPath\MyFile.txt'
WITH (
DATAFILETYPE = 'widechar',
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
-- This doesn't work
DECLARE @cmd varchar (8000)
DECLARE @FName varchar (100)
DECLARE @FPath varchar (500)
SELECT @FName = 'MyFile.txt'
SELECT @FPath = 'MyPath\'
SELECT @cmd = 'bcp MyDatabase..MyView IN "' + @FPath + @FName + '" -w -T -S' +@@ServerName
EXEC master..xp_cmdshell @cmd
The bcp chunk gives me:
NULL
Starting copy...
NULL
0 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 53046
NULL
And, indeed, it copied no rows. I've tried passing in a -t\| because the files are pipe delimited but then it won't even run. The row terminator is the default and SQL Server tells me that the file is widechar.
Did I miss something?
Also, I do have the archive piece. However, when I try to run it I get annoying access errors. It may work if I run it off of Prod with the correct login but I haven't gotten that far with all of this yet.