As commented by Solomon Rutzky, the code I've made before didn't work with english phrases, so I've refactored it, and now it works on all the examples:
create or alter function reverse_english_only(@str nvarchar(max))
returns nvarchar(max) AS
begin
declare @output nvarchar(max) = N''
declare @size int = DATALENGTH(@str)
declare @iterate int = 1
declare @block_start int = 1, @block_type char(1), @current NCHAR(1)
set @block_type = case when UNICODE(@str)>=1424 and UNICODE(@str)<=1524 then 'H' else 'E' end
while @iterate < @size
BEGIN
set @current = SUBSTRING(@str, @iterate,1)
--Hebrew
if UNICODE(@current) >=1424 and UNICODE(@current)<=1524
BEGIN
if @block_type='E'
begin
set @output += REVERSE(SUBSTRING(@str, @block_start, @iterate-@block_start))
set @block_type = 'H'
set @block_start = @iterate
end
END
--Non-Hebrew
ELSE
BEGIN
if @block_type = 'H'
begin
set @output += SUBSTRING(@str, @block_start, @iterate-@block_start)
set @block_type='E'
set @block_start=@iterate
end
end
set @iterate = @iterate + 1
END
if @block_type = 'H'
set @output += SUBSTRING(@str, @block_start, @iterate-@block_start)
else
set @output += REVERSE(SUBSTRING(@str, @block_start, @iterate-@block_start))
return @output
END
GO
select
dbo.reverse_english_only(N'שורת EDULCNI - הפעלת עמודה'),
dbo.reverse_english_only(N'מסך MOOZ דינמי'),
dbo.reverse_english_only(N'סימון מצררים/PRM'),
dbo.reverse_english_only(N'yraeL''O .srM - הפעלת עמודה'),
dbo.reverse_english_only(N'שורת OWT ENO - הפעלת עמודה')
SELECT CONVERT(VARBINARY(MAX), [{column_name}]) FROM ...
.CONVERT
function I noted in my previous comment. 2) Is there ever any punctuation within the English words, such as commas, periods, apostrophes, etc? (example:Mrs. O'Leary
) Or, is there ever multiple English words grouped together? (example:INCLUDE ZOOM
) If so, please provide an example (both what you see and theVARBINARY
output. Thanks.