我在开发存储过程时遇到此错误
无法执行varchar值到varchar的隐式转换,因为由于排序规则冲突而无法解析值的排序规则。
声明就像这样
Select City COLLATE DATABASE_DEFAULT AS Place, State, Country FROM DEPT1
UNION ALL
Select '' AS Place, 'Arizona' As State, Country FROM DEPT2
但如果如果这样做也会给出同样的错误
Select City COLLATE DATABASE_DEFAULT AS Place, State, Country FROM DEPT1
UNION ALL
Select '' COLLATE DATABASE_DEFAULT AS Place, 'Arizona' As State, Country FROM DEPT2
实际上这段代码是由其他人编写的,我只是编辑代码,不知道为什么他添加了COLLATE DATABASE_DEFAULT但如果我删除它也会给出同样的错误
无法执行varchar值到varchar的隐式转换,因为由于排序规则冲突而无法解析值的排序规则。
答案 0 :(得分:52)
你最有可能在两个地方都需要COLLATE。
Select City COLLATE DATABASE_DEFAULT AS Place, State, Country FROM DEPT1
UNION ALL
Select '' COLLATE DATABASE_DEFAULT AS Place, 'Arizona' As State, Country FROM DEPT2
编辑:如果你在一个地方获得它,你可能需要在每个字符串上
Select
City COLLATE DATABASE_DEFAULT AS Place,
State COLLATE DATABASE_DEFAULT AS State,
Country COLLATE DATABASE_DEFAULT AS Country
FROM DEPT1
UNION ALL
Select
'' COLLATE DATABASE_DEFAULT,
'Arizona' COLLATE DATABASE_DEFAULT ,
Country COLLATE DATABASE_DEFAULT
FROM DEPT2
EDIT2:
这是因为您的列排序规则可能与数据库排序规则不同。所以“City”有一个整理,但字符串常量有另一个。
答案 1 :(得分:1)
ALTER TABLE DEPT1和DEPT2,以便生成的表定义不包含任何COLLATE