Solved

BCP Using a variable in the Where Clause

Posted on 2014-01-17
1
1,075 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
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now