本文介绍了为什么不显式COLLATE覆盖数据库排序规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在SQL Server 2008 R2开发人员上,服务器默认排序规则为Cyrillic_General_CI_ASI am on SQL Server 2008 R2 dev, server default collation is Cyrillic_General_CI_AS在SSMS中执行 选择'éÉâààÀëËçæà'COLLATE Latin1_General_CS_AS 或Executing in SSMS SELECT 'éÉâÂàÀëËçæà' COLLATE Latin1_General_CS_ASorSELECT 'éÉâÂàÀëËçæà' COLLATE Latin1_General_CI_AI输出 eEaAaAeEc?a on(使用/使用dbName)默认排序规则Cyrillic_General_CI_AS éÉââàÀëËçæà的数据库上默认排序规则Latin1_General_CI_AS推荐答案首先将查询中的那些字符文字在数据库设置的任何排序规则下转换为varchar字符串,然后在归类强制转换生效。Those character literals in your queries are first converted to varchar strings under whatever collation the database is set for, and then your collation cast takes effect.如果要传递这样的字符文字并确保忠实地代表所有字符,则最好将它们作为nvarchar文字传递:If you want to pass such character literals and ensure all characters are faithfully represented, it's better to pass them as nvarchar literals:create database CollTest collate Cyrillic_General_CI_ASgouse CollTestgoSELECT 'éÉâÂàÀëËçæà' COLLATE Latin1_General_CS_ASSELECT 'éÉâÂàÀëËçæà' COLLATE Latin1_General_CI_AIgoSELECT N'éÉâÂàÀëËçæà' COLLATE Latin1_General_CS_ASSELECT N'éÉâÂàÀëËçæà' COLLATE Latin1_General_CI_AIgo输出:-----------eEaAaAeEc?a(1 row(s) affected)-----------eEaAaAeEc?a(1 row(s) affected)-----------éÉâÂàÀëËçæà(1 row(s) affected)-----------éÉâÂàÀëËçæà(1 row(s) affected) 这篇关于为什么不显式COLLATE覆盖数据库排序规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
05-17 23:20