Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

BCP Using a variable in the Where Clause

Posted on 2014-01-17
1
Medium Priority
?
1,471 Views
Last Modified: 2014-01-17
I need to pass a variable to bcp using queryout

This is being called from within a stored procedure like this:

While @minpo < @maxpo
Begin

SET @CmdString = 'bcp "SELECT * FROM #Outputtmp where ponumber = "" @minpo """ queryout "' + @Directory + '\' + @FileName + '" -c -U' + @User + ' -P' + @Pass


SELECT TOP 1 @minPO = PONumber
FROM #outputtmp
WHERE PONumber > @minpo
ORDER BY PONumber

End

@CmdString ends up looking like this:

bcp "SELECT * FROM #Outputtmp where ponumber = "" @minpo """ queryout "c:\570\101370000570.oro" -c -Usoandso -PN/A

Can anyone help me with this.  

Thanks.
0
Comment
Question by:sherbug1015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 39788688
this should work better:
SET @CmdString = 'bcp "SELECT * FROM #Outputtmp where ponumber = ''' + @minpo + ''' queryout "' + @Directory + '\' + @FileName + '" -c -U' + @User + ' -P' + @Pass

Open in new window

0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question