Escaping characters

Hello

I have a long list of strings that have the word STR inside them, commas, single quotes, etc etc.

I cannot escape each one of these.

Is there an easy way to use these strings literally?

Thanks!

please provide sample data

It's confidential but I can provide some surrogate data:

STR, TOR, ROT
TR - TH
MK - (ME)
SE & YK
TJ; KT
T. & Y.

Lot's of lines and different permutations!

Any idea?

How About Using

Regular Expressions ...

And what is the final result you want to see

I was to use the above list of strings into this statement:

NOT IN
('STR, TOR, ROT',
'TR - TH',
'MK - (ME)',
'SE & YK',
'TJ; KT',
'T. & Y.')

The problem is that SSMS does not recognise them as strings as it does not highlight them in red. How can I use the above strings literally as strings?

Thanks!

"Does not highlight them in red" not sure if that has anything to do with your problem.

But the strings you are trying to exclude are strings delimited with comma. 'STR, TOR, ROT are you expecting it to exclude STR ROT and TOR?

Please provide non confidential sample data. Otherwise our answers might be confidential too :grin:

1 Like

I want to exclude the string STR, TOR, ROT literally.

SSMS highlights the word STR, and some other parts of the strings with various colours.

Can you confirm these strings will be taken literally if I simply include each in single quotes (and separate them with commas and include all of them in brackets)?

Or do I need to escape something or do anything else? The different coloring of SSMS worries me.

I already provided above? Both the strings I want to exclude and the code I wrote to exclude them.

Ah I fixed it!

Somewhere in the middle of the strings, there was a ' which I had to escape with another '.

Thanks

Great cause it made no sense to me

2 Likes

Hi sqlor

I have faced this single quote in middle of string issue

Many Many times

2 Likes