Please help me write a PATINDEX or LIKE statement to match characters other than:
I plan to use this in a scalar UDF with an nvarchar(200) input, which processes the input by:
This will be used to create part of an SEO-friendly URL e.g. /my-seo-friendly-url-1
. I am very confident in doing this UDF, apart from the pattern-matching part. Regex-like stuff confuses me! Please help.
Thanks for your help in advance.
Probably best done in your application but
SELECT PATINDEX('%[^-a-zA-Z0-9.~_]%', @YourString COLLATE Latin1_General_BIN)
should do it in TSQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With