How to write Bcp command to insert data in to a table

240 pts.
Tags:
BCP Utility
SQL
SQL 2005
Hi, I have a file which contains the data 2:23:3#1:2:4#2:3:5 i have to insert the data in to the table in multiple rows from a single file as #--indicates to be inserted in next row : --indicates next column column1 column2 column3 2 23 3 1 2 4 2 3 5 I need to use BCP. Can any one let me know how to write the BCP command for this in t-sql Thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.

declare @bcp as varchar(200)

set @bcp = ‘bcp DBname.dbo.tablename in \\server\filepath\tmpTestFile.txt -c -t : -r # -Sserver -Ulogin -Ppassword

exec master..xp_cmdshell @bcp

bcp needs full path to table and doesn’t like ##temptables

switches
Field terminator -t
Row terminator -r

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • GIG
    Thanks for your inputs..
    240 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following