?
Solved

BCP Using a variable in the Where Clause

Posted on 2014-01-17
1
Medium Priority
?
1,361 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

771 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