use tempdb

drop table #ttx

-- create database
create table #ttx (
    ix integer,
    cx varchar(10) -- collate Latin1_General_CI_AS_KS_WS,
    __icx as upper(substring(cx, 1, len(replace(replace(replace(cx, CHAR(9), ' '), CHAR(10), ' '), CHAR(13), ' ')))),
)

create index id_cx on #ttx (cx);
create index id__icx on #ttx (__icx);

-- populate table
declare @ix as integer = 0
while  @ix <= 256
begin
	insert into #ttx (ix, cx) values (@ix, 'a' + char(@ix) + 'z')
	set @ix = @ix + 1
end

-- run queries
print('Run query ascending case-insensitive query')
select ix, cx from #ttx order by cx

print('Run query ascending case-sensitive query')
select ix, __icx from #ttx order by __icx
    
-- print('Run query descending case-insensitive query')
-- select ix, cx from #ttx order by cx desc

-- print('Run query descending case-sensitive query')
== select ix, __icx from #ttx order by __icx desc

print('all done')
