Как насчет этого? Если это помогает, пожалуйста, вверх голосовать мой ответ, чтобы я мог получить много точек и выглядеть круто :)
if schema_id(N'utility') is null
execute (N'create schema utility');
go
if object_id(N'[utility].[get_some]'
, N'TF') is not null
drop function [utility].[get_some];
go
/*
select [lead], [lag] from [utility].[get_some] (N'return_abcdeandabcde_this', N'and', 5, 5);
select [lead], [lag] from [utility].[get_some] (N'return_a c eanda c e_this', N'and', 5, 5);
select [lead], [lag] from [utility].[get_some] (N'return_ bcd and bcd _this', N'and', 5, 5);
*/
create function [utility].[get_some] (
@input [nvarchar](max)
, @search [nvarchar](max)
, @lead_length [int]
, @lag_length [int])
returns @data table (
[lead] [nvarchar](max)
, [lag] [nvarchar](max))
as
begin
insert into @data
([lead],[lag])
select substring(@input
, charindex(@search
, @input) - @lead_length
, @lead_length) as [lead]
, substring(@input
, charindex(@search, @input) + len(@search)
, @lag_length) as [lag];
return;
end;
пойти
А что ваш язык? – Larme