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%''
.
Starting BCP from T-SQL: handling quotes
-
31-05-2022 - |
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 !
Solution 2
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