April 1, 2009 at 9:35 am
Update myTable
Set strwhere = 'C.IT_Code IN ('A','E','C','P','R','O') AND SP.Status='S' and SP.PayDT <> '********' AND (NOT (C.ContractStatus IN ('D', 'X')))'
where
ReportID = 800
The above sql statement gives an error because of the apostrophe. How do I handle the apostrophes so that the update statement runs correctly?
thanks
April 1, 2009 at 9:36 am
Any idea?
April 1, 2009 at 9:44 am
You escape quotes by doubling them.
Set strwhere = 'C.IT_Code IN (''A'',''E'',''C'',''P'',''R'',''O'') AND SP.Status=''S'' and SP.PayDT <> ''********'' AND (NOT (C.ContractStatus IN (''D'', ''X'')))'
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 1, 2009 at 11:19 am
My question would be why are you using dynamic SQL? That is why you are having a problem with quotes and Gail has given you the solution for that, if dynamic SQL is required.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
April 1, 2009 at 11:43 am
Hi Jeffrey
it looks to me he is storing all these different queries/conditions in a table.
Its not a good idea. What it is your actual requirement??
April 1, 2009 at 12:43 pm
Actually the Gail's response worked.
Thank you
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply