How to escape the single quote in the single quoted string
I have a stored procedure like below:
Call USER.SP('select * from Sample.Person where SSN='aaaaa'','0','S')How could I escape the single quotes for aaaaa? I try double single quotes but in vain.
Thanks you.
Comments
$replace is your friend here so you can just do:
set escaped=$replace(str,”’”,”’’”)
You will need to parse out the single quote at the start of the statement so you do not double this quote too.
But so?
Call USER.SP('select * from Sample.Person where SSN=''aaaaa''','0','S')The double single quote does not work.
I wonder if the problem is package name and it should be Sqluser instead of User. http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GOBJ_defpersobj_sqlproj_pkg
It's a bit difficult to answer correctly because I still not sure what are you doing, I would try ''''aaa''aaa'''' or ''''aaa''''''aaa'''' or even ''''aaa''''''''aaa''''
Hi,
You must use 3 single quotes:
Call USER.SP('select * from Sample.Person where SSN='''aaaaa''' ','0','S')I try triple single quote in $system.SQL.Shell(), but it still does not work.
ERROR #5540: SQLCODE: -1 Message: ) expected, ? found^ Call USER. SP ( ? ? [Generate+1247^%SYS.DynamicStatement:SAMPLES]
So strange query. But anyway if you want to get double single quotes, should double each one. So, it should be ''''
Something like this.
Call USER.SP('select * from Sample.Person where SSN=''''aaaaa'''' ','0','S')
Thanks, it works now.
If so, do not forget to mark the answer as accepted.
BTW, what if i would like to compare SSN with aaa'aa (ie: single quote is also the content I would like to compare.) ?
Thanks.