0

I am using Excel to run paramaterized SQL Server Queries. Everything works fine, except when the parameter has a apostrophe. For example, let's say my syntax is this

Select * from testtable where arovaica = @passedvalue

And in Excel @passedvalue is set to Michael's I get an error of

Incorrect syntax

How should I encapsulate this variable with an apostrophe in order for SQL to compile properly?

Community
  • 1
  • 1

1 Answers1

0

Try a replace as suggested here

    Select * from testtable where arovaica = REPLACE(@passedvalue, '', '''')
Community
  • 1
  • 1
M O'Connell
  • 487
  • 5
  • 18
  • To my understanding replace will not work, as it seems that would remove the quote all together. I think, judging from your comment, I just need to double the quote so SQL Server "sees" the string appropriately. – StarsFlyFree FromCozyNights Nov 29 '16 at 02:45
  • `Replace` should work but I've the got the apostrophes reversed `Select REPLACE('Michael''s', '', '''')`. Editing answer – M O'Connell Nov 29 '16 at 02:50