0

I have a question about escape characters for quotes in a select statement.

I know how to do this in PowerShell but not SQL. I have a list of serial numbers from computers.

I would like to search a column based on the last 7 digits of the serial. The best way I know how to do this is with select right

select RIGHT('XYZMN605GMN6',7)

I am trying to run it like so

query....
where <ColumnName> like '%(select RIGHT('XYZMN605GMN6',7))'

This of course formats it all to one string. How can I escape the quotes around the parenthesis so it still runs the select but appends the quotes around it with the wildcard at front? Or maybe there is a better way of doing it I don't know?

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • This isnt a duplicate of that one. All that does is it output my select statement into a column as string. Thats not what i want – KeetsScrimalittle Feb 03 '20 at 20:15
  • That duplicate answer does NOT even come close to answering this question... Try removing the outer single quotes and the select is not needed. Something like: `where like '%' + RIGHT('XYZMN605GMN6',7)` – dvo Feb 03 '20 at 20:16
  • @dvo Ya that worked. Thanks for helping me despite the post being closed in 10 seconds. – KeetsScrimalittle Feb 03 '20 at 20:20
  • Happy to help... This question should never have been marked as a duplicate of that question... – dvo Feb 03 '20 at 20:22
  • What you asked here was how to escape single quotes; that is what the marked duplciate does. *"SQL how to use escape character for quotes"* (from the title), *"How can I escape the quotes around the parenthesis"* (from the question). If that isn't what you're after, then the question shouldn't be asking about that. I'll happily reopen, but the question as it stands asks how to escape single quotes and need editting to reflect the 8real* question if so. This is why i closed it, @dvo . – Thom A Feb 03 '20 at 20:26
  • 1
    @larnu no hard feelings. I didnt know exactly how to phrase the question in the title. I tried my best to explain it in the body. cheers – KeetsScrimalittle Feb 03 '20 at 20:27

0 Answers0