0

问题:我有一个由 .NET 应用程序创建的程序(简化):

create procedure #SaveData
@InValue varchar(128)
as
begin
    insert into Production.TargetTable (PREFIX_Value) select @InValue
end

问题是,数据库使用SQL_SLOVAK_CP1250_CI_AS排序规则。TempDB 使用默认的SQL_Latin1_General_CP1_CI_AS排序规则。

问题简化:

-- this doesnt work, returns RTC
create procedure #SaveData
@InValue varchar(128)
as
begin
    select @InValue
end

-- this doesnt work, returns RTC
create procedure #SaveData
@InValue varchar(128)
as
begin
    select @InValue collate SQL_SLOVAK_CP1250_CI_AS
end

-- this does work, returns ŘŤČ
create procedure SaveData
@InValue varchar(128)
as
begin
    select @InValue
end

这导致RTC被保存,而不是测试字符串ŘŤČ 。当我从过程名称中删除 # 并且不将其创建为临时过程时,一切正常。

现在,一种可行的修复方法是将参数类型从 varchar 更改为 nvarchar。但这将是很多工作(许多不同的程序)。有没有可行的全球方法?

谢谢你,祝你有美好的一天

4

1 回答 1

0

问题出在列排序规则中。传递给它的任何值都将其排序规则更改为列排序规则:

declare @table table(txt varchar(10) collate SQL_Latin1_General_CP1_CI_AS)
insert into @table values ('ŘŤČ' collate SQL_SLOVAK_CP1250_CI_AS)
--result will be changed, even with explicit collation
select * from @table
go

declare @table table(txt varchar(10) collate SQL_SLOVAK_CP1250_CI_AS)
insert into @table values ('ŘŤČ')
--correct output
select * from @table
go

因此,您必须更改列中的排序规则:

alter table TABLE_NAME alter column TextCol varchar(...) collate SQL_SLOVAK_CP1250_CI_AS 
于 2017-12-08T10:25:32.830 回答