是否可以获得没有标志CI,CS,AI,AS的列整理字符串?
例如:
如果我们“Latin1_General_100_CS_AS”我需要“Latin1_General_100”而不需要“_CS_AS”。
感谢。
答案 0 :(得分:0)
CS =区分大小写CI =大小写不敏感您需要拥有一个或另一个。
AS =重音敏感,AI =重音不敏感。
这些代码指定了如何排序。您需要选择CI或CS以及AS或AI
答案 1 :(得分:0)
您可以使用SQL替换功能删除' _CI'的实例。在您的查询中。
例如,下面的代码将从排序规则名称中删除_CI和_AI。您可以使用类似的逻辑删除您不想要的其他字符。
SELECT name, REPLACE(REPLACE(name, '_CI',''), '_AI','') description FROM sys.fn_helpcollations();
答案 2 :(得分:0)
在这里,您可以通过名称表(例如整理名称)排除任何您想要的falg。如果您愿意,您可以准备一个程序或功能,以便在批量生产中更轻松。
-- declaration of the input table
declare @input as table (name varchar(max));
-- declaration of the output table
declare @output as table (name varchar(max));
-- declaration of the table with flags you want to exclude from names
declare @exclude as table (flag varchar(max));
-- put flags you want to exclude into array
insert into @exclude (flag)
values ('CI'), ('CS'), ('AI'), ('AS');
-- put some collations into input table (as example for testing)
insert into @input
select distinct name
from sys.fn_helpcollations();
-- now we need to loop over all value in exclude table
declare @excludeCursor as cursor;
declare @flag as varchar(max);
set @excludeCursor = cursor for
select flag
from @exclude;
open @excludeCursor;
fetch next from @excludeCursor INTO @flag;
while @@FETCH_STATUS = 0
begin
update @input
set name = replace(name, concat('_', @flag), '')
where name like concat('%_', @flag)
or name like concat('%_', @flag, '_%')
-- The where clause above ensure that you replace exactly the flag added to your exclude table.
-- Without this caluse if you want to excldue for example a BIN flag and you have a BIN and BIN2 flags in your names
-- then the '2' character from the BIN2 will stay as a part of your collation name.
fetch next from @excludeCursor INTO @flag;
end
close @excludeCursor;
deallocate @excludeCursor;
-- prepare the output table with distinct values
insert into @output
select distinct name
from @input;
-- print the output
select *
from @output