0

Consider the following table keywords:

keyword
--------------------------------
(test1 AND ("test2" OR "test 3"))
"test4"
"test 5"
(test 5)

I need to select this table, but in the output there should have happened some clean up, namely:

  • if there is a space in a keyword, and the keyword is surrounded by quotes, keep the quotes
  • if there is no space in a keyword, and the keyword is surrounded by quotes, remove the quotes

Desired output:

keyword
--------------------------------
(test1 AND (test2 OR "test 3"))
test4
"test 5"
(test 5)

I believe I need a regular expression in my select, but have no experience here. Can you help me out?

Pr0no
  • 3,910
  • 21
  • 74
  • 121
  • 1
    This is not an easy task in SQL, and even more in SQL Server, that has almost no regexp support. You would probably be better off performing this in your application. – GMB Apr 02 '20 at 10:24
  • There are a variety of ways to add regular expression support to SQL Server some of which are discussed [here](https://stackoverflow.com/questions/8928378/using-regex-in-sql-server). I did this quite a few years ago for use within Crystal Reports detailed [here](https://blogs.sap.com/2013/01/31/regular-expressions-within-a-crystal-report/). Just a few more possibilities for you to consider. – Isaac Apr 02 '20 at 10:52

0 Answers0