Hey guys,
I know there have been plenty of posts on this topic. I did my research and have my Query outputting to a text file as I wanted. However I have a question with adding something to my command.
Here is my command that is working:
EXEC XP_CmdShell 'BCP "Select code, desc From DATABASE.dbo.ta ble" queryout "C:\test.tx t" -c -T'
I want to add a "WHERE" command to this line, where I have a value equal to something...Exa mple:
WHERE mat = '8888'
I know I need to declare "mat" as part of a different table in the database. Here is what I have at the moment...
EXEC XP_CmdShell 'BCP "Select code, desc From DATABASE.dbo.ta ble, DATABASE.dbo.Ot herTable b WHERE b.mat = '8888'" queryout "C:\test.tx t" -c -T'
I am getting a syntax error where '8888' is. I know it is because of the ' character that is commenting out my equal to value. What is the correct syntax to do this? I have tried many things and still haven't gotten it to work. Any help is appreciated! Thanks everyone!
I know there have been plenty of posts on this topic. I did my research and have my Query outputting to a text file as I wanted. However I have a question with adding something to my command.
Here is my command that is working:
EXEC XP_CmdShell 'BCP "Select code, desc From DATABASE.dbo.ta ble" queryout "C:\test.tx t" -c -T'
I want to add a "WHERE" command to this line, where I have a value equal to something...Exa mple:
WHERE mat = '8888'
I know I need to declare "mat" as part of a different table in the database. Here is what I have at the moment...
EXEC XP_CmdShell 'BCP "Select code, desc From DATABASE.dbo.ta ble, DATABASE.dbo.Ot herTable b WHERE b.mat = '8888'" queryout "C:\test.tx t" -c -T'
I am getting a syntax error where '8888' is. I know it is because of the ' character that is commenting out my equal to value. What is the correct syntax to do this? I have tried many things and still haven't gotten it to work. Any help is appreciated! Thanks everyone!
Comment