Supported ISO language codes in SQL server

492 Views Asked by At

• How can I list the supported regional ISO codes per the version I work on?

I need to check an ISO 639-1 (2 characters) language code to see if it is supported. You don't get a default reply for versions prior to 2019. It throws an error.

Example for the requirement:

select format(current_timestamp,'dd-MMMM-yyyy','es')
select format(current_timestamp,'dd-MMMM-yyyy','mn')
select format(current_timestamp,'dd-MMMM-yyyy','ii')
select format(current_timestamp,'dd-MMMM-yyyy','oo')
select format(current_timestamp,'dd-MMMM-yyyy','qq')

The above will return 2 errors on (my) v.2016 – The culture parameter 'oo' provided in the function call is not supported. The culture parameter 'qq' provided in the function call is not supported.

This doesn't match the definitions listed in sys.syslanguages And that table does not include the iso code either.

Thank you!

1

There are 1 best solutions below

0
On

Per martin's answer, this differs from one environment to another. The ugly way will work, yet a list from the internal tables to work on would be nice.

drop table if exists #SupportedLanguages;
create table #SupportedLanguages(Lang varchar(2));
declare c cursor fast_forward local for
select concat(a.value,b.value)
from string_split('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z',',')a
    cross apply string_split('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z',',')b
open c;

declare @c varchar(2), @cmd varchar(100);
fetch next from c into @c;

while @@FETCH_STATUS = 0
begin
    select @cmd = concat('select format(current_timestamp,''dd-MMMM-yyyy'',''', @c, ''')')
    begin try
        exec(@cmd);
        insert into #SupportedLanguages values(@c);
    end try
    begin catch
    end catch
    fetch next from c into @c;
end;

close c;
deallocate c;