I have a problem extracting substrings. I'm logging some SQL queries in my database and need to filter that.
Possible strings can look like these 2 examples:
1. [DatabaseName].[dbo].[TableName$TableExtra]
2. "DatabaseName".dbo."TableName$TableExtra"
I've tried this:
DECLARE @c AS NVARCHAR(MAX) =
'
"DatabaseName".dbo."TableName$TableExtra"
'
SELECT
SUBSTRING(SUBSTRING(@c, PATINDEX('%"DatabaseName".dbo."%', @c) + 20, 100), 1,
PATINDEX('%"%', SUBSTRING(@c, PATINDEX('%"DatabaseName".dbo."%', @c) + 20, 100)) - 1)
That will only work with the second example but with the first one.
Can anyone help me how to write the filter that works for both samples?
Have a nice day