• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1548
  • Last Modified:

BCP Using a variable in the Where Clause

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
sherbug1015
Asked:
sherbug1015
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now