We help IT Professionals succeed at work.
Get Started

MS SQL Query - Using BCP to import files into MS SQL, issues with delimiters!

246 Views
Last Modified: 2012-05-08
For the most part the issue where I am having trouble with is this:

set @Query ='bcp CHRIS2.dbo.'+@Tablename + ' in "'+ @Filename+'" -T -q -r\n -t, -c'
set @Query = 'MASTER.DBO.xp_cmdshell '+ "'"+  @query +"'"

As you see here, the -t is the delimiter that splits the columns up, and -r is the rows. -r here is \n (newline) and -t is a comma. (,)

Issue if, If I use something like:

set @Query ='bcp CHRIS2.dbo.'+@Tablename + ' in "'+ @Filename+'" -T -q -c -r\n -t' + CHAR(124)
set @Query = 'MASTER.DBO.xp_cmdshell '+ "'"+  @query +"'"

or

set @Query ='bcp CHRIS2.dbo.'+@Tablename + ' in "'+ @Filename+'" -T -q -r\n -t| -c'
set @Query = 'MASTER.DBO.xp_cmdshell '+ "'"+  @query +"'"

It does not work! The delimiter is | in the files but I cannot get the query to run because I am guessing that | is a special character that SQL uses. I end up with invalid syntax command etc. But I garentee its because of the |..

Any help?
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE