显示标签为“file_path”的博文。显示所有博文
显示标签为“file_path”的博文。显示所有博文

2012年2月25日星期六

bcp bulk upload

Hello !!

Can anyone help, I am trying to do bulk upload:

EG.

set @.BULK = 'bcp "DQ_Central.dbo.tbl_CLI_UPLOAD" in "' + @.file_path + '" -S' + @.Server + ' -U' + @.User + ' -P' + @.PSW

and am getting this output message

Enter the file storage type of field service_number [char]:

Any one have any ideas ?!? Thanks u for yr helpyou forgot to specify the input file type, - character or native (-c or -n).

but you, you can do the same thing with bulk insert. this way you won't have to through your @.BULK at xp_cmdshell and get completely frustrated with char(39).

2012年2月23日星期四

BCP and column defaulting

I am bringing data from a file using bcp as below in a stored procedure.
SET @.SQLString = 'BCP STAGING IN "' + @.file_path + '" -c -F2 -Uxyz -Pxyz'
EXEC master..xp_cmdshell @.SQLString
The table has only one column varchar (1024). I need to add one more column
called code which i can pass to the stored procedure but need to be added to
the staging table when rows gets inserted. Because the stored procedure
could be called at the same time with two different codes. So based on what
code is passed to the SP all the rows inserted by bcp in that instance of
the SP should have that code. How would i do this?
Thanks,
DavidHi
You may want to look at using the BULK INSERT command and load it into a
temporary table.
CREATE TABLE staging( id int not null,
[name] varchar(10),
col1 varchar(80),
col2 varchar(80) )
CREATE PROCEDURE MyLoad ( @.Name varchar(10), @.filename varchar(256) )
AS
BEGIN
CREATE TABLE #test ( id int not null,
col1 varchar(80),
col2 varchar(80) )
EXEC ('BULK INSERT #test FROM ''' + @.filename + '''')
INSERT INTO Staging ( id, name, col1, col2 )
SELECT id, @.Name, col1, col2
FROM #test
END
EXEC MyLoad 'Test1', 'C:\temp\test.txt'
John
"Viji" wrote:

> I am bringing data from a file using bcp as below in a stored procedure.
> SET @.SQLString = 'BCP STAGING IN "' + @.file_path + '" -c -F2 -Uxyz -Pxyz'
> EXEC master..xp_cmdshell @.SQLString
> The table has only one column varchar (1024). I need to add one more colum
n
> called code which i can pass to the stored procedure but need to be added
to
> the staging table when rows gets inserted. Because the stored procedure
> could be called at the same time with two different codes. So based on wha
t
> code is passed to the SP all the rows inserted by bcp in that instance of
> the SP should have that code. How would i do this?
> Thanks,
> David
>
>