--:SetVar Function "AUX:StartsFromSpace.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:StartsFromSpace.Ext' )
   drop function [AUX:StartsFromSpace.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:StartsFromSpace.Ext]( @String nvarchar(max), @TreatBlankAsEmpty bit=0 )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING, IF STRING STARTS FROM SPACE (EXT.VERSION):
#
# === Usage: ===
# dbo.[AUX:StartsFromSpace.Ext]( <String>, 1 )
# dbo.[AUX:StartsFromSpace.Ext]( <String>, 0 )
#
==================================================================================================*/

if @String is null or DATALENGTH( @String )=0
   return 0

if SUBSTRING(@String,1,1) <> '' -- has heading non-space
   return 0

if @String = '' -- the string is blank (at this place)
   return
      case @TreatBlankAsEmpty
         when 1 then 0
         when 0 then 1
         else null
      end

return 1

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:StartsFromSpace.Ext]( N'qwerty', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( N' qwerty', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( ' ', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( '', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( null, 1 ) 'Starts from space'
*/
/*
select dbo.[AUX:StartsFromSpace.Ext]( N'qwerty', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( N' qwerty', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( ' ', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( '', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( null, null ) 'Starts from space'
*/
