0

I want to replace column name on where clause. But the problem is be replace string has quotation mark.

TBL407.[POSTINGDATE] >= '2023-01-01 00:00:00' AND TBL407.[POSTINGDATE] <= '2023-01-31 23:59:59'

It should be replace with [POSTINGDATE] -> [Posting Date]

When I tried to replace like this;

 REPLACE('TBL407.[POSTINGDATE] >= '2023-01-01 00:00:00' AND TBL407.[POSTINGDATE] <= '2023-01-31 23:59:59'','POSTINGDATE', 'Posting Date')

Of course it's not working. The quotation mark break this. How can I do that?

Tushar
  • 3,527
  • 9
  • 27
  • 49
  • 2
    I think you are confused about what the REPLACE function does. You can't just use it arbitrarily change your where clause like this. – Sean Lange Mar 24 '23 at 13:49
  • Actually, where clause comes from project. I need to change this. Unfortunately, we cannot intervene within the project. I wonder is that possible this? – caglar.boran Mar 24 '23 at 13:53
  • 1
    replacing goes only with dynamic sql or a sql proxy who will analyse the query string and replace it. – nbk Mar 24 '23 at 14:04
  • I just wondered is that possible. Thanks! – caglar.boran Mar 24 '23 at 14:12
  • The duplicate link answers your immediate question: double up `'` to escape them `''`. But that wont help you unless you are using dynamic SQL, and I honestly hope you are not as it's pretty advanced and complex, and not usually necessary. – Charlieface Mar 24 '23 at 15:54

0 Answers0