:SetVar Function "AUX:SpecialLanguage"
:r $(DropFunctionScript_AUX)
create function [$(Function)]()
returns $(dt_Name_AUX)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# SPECIAL LANGUAGE NAME FROM CONNECTION STRING —
# FOR SITUATION, WHEN THE LANGUAGE IS NOT SUPPORTED BY MS-SQL-SERVER:
#
# === Examples: ===
# Connection string: "...;Application Name=...#Old Slavonic;..."
# Connection string: "...;Application Name=...#OSL;..."
#
# === Usage: ===
# dbo.[AUX:SpecialLanguage]()
#
==================================================================================================*/
declare @AppName sysname
select @AppName = [program_name] from [sysprocesses] (nolock) where [spid] = @@SPID
if @AppName is null or CHARINDEX('#',@AppName)=0
   return null
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
declare @L int, @P int
set @L = LEN( @AppName )
set @P = @L
while @P > 0
begin
   if SUBSTRING(@AppName,1,1)='#' break
   set @P = @P - 1
end
if @P > 0 and @P < @L
   return dbo.[AUX:LocalLanguageNameFromCulture]( SUBSTRING( @AppName, @P+1, @L-@P ) )
return null
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:SpecialLanguage]() 'Special language (from connection string)'
*/
