Reputation: 879
I have the following string which varies in length depending on database and table name:
[servername].[databasename].[dbo].[tablename.csv]
I would like to extract only the table name after "[dbo]." and before ".csv]".
Any help would be greatly appreciated.
Upvotes: 0
Views: 50
Reputation: 1689
declare @str varchar(200) = '[servername].[tablename].[dbo].[tablename.csv]'
select substring(@str,(PATINDEX('%dbo%',@str)+6),
(PATINDEX('%.csv%', @str) - (PATINDEX('%dbo%',@str)+6)))
Upvotes: 1