Question

I am trying to run the following command from SSMS:

EXEC xp_cmdshell 'bcp "SELECT *  FROM [erpSQL].[dbo].[Documents]  WHERE NoDoc like 'F%' and DateDoc = cast(GETDATE() as DATE)" queryout "d:\test.txt" -c -t -T ' 

and of course I have an error with like 'F%', saying Incorrect syntax near 'F'.
How do I handle that ?
I tried doubling the single quotes, but it's not that.
I tried using doubles quotes instead, that gives me an error near AND.

Thanks !

Was it helpful?

Solution 2

You need to escape the 'F%' paramenter. You can do this by adding anoter ' at the begining and the end of your current parameter, like this ''F%''.

OTHER TIPS

Retry to use the escape sequence for single quote:

WHERE NoDoc like ''F%''

It must work!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top