April 23, 2012 at 2:13 am
I have this query where I'm trying to get data into Test.csv from table TableName where ColA has value of sqlnaive.
bcp "select * from DatabaseName.dbo.TableName where ColA ='sqlnaive'" queryout "C:\DataMigration\Test.csv" -SServerName -T -c
Now I want to run it with a parameter where whatever value is passed it should work. Is it possible ?
April 23, 2012 at 3:29 am
How are you executing that command? From a batch file? If that's the case, you can refer to the values of parameters passed to the batch file as %1 (first parameter), %2 (second parameter) etc.
April 23, 2012 at 5:13 am
It worked perfectly. Thanks a lot. 🙂
April 23, 2012 at 6:23 am
September 28, 2012 at 3:07 am
Hi, I want to do the same thing from within a procedure.
Trying to do something like the following:
Declare @var_XML xml
:
:
:
:
Select @var_XML = (Select * From Tab_Name For XML PATH ('privilege'))
-- Select Select @var_XML -- This works fine.
-- But the following will not work (says @var_XML must be declared.
EXEC xp_cmdshell 'bcp "Select Select @var_XML " queryout "C:\tab_name.xml" -S MyServer -U sa -P pwd -c'
Is there a way to get this to work?
Many thanks
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply