首页 > 数据库技术 > 详细

Chinese_PRC_CI_AS and SQL_Latin1_General_CP1_CI_AS类型错误

时间:2014-05-26 07:32:16      阅读:606      评论:0      收藏:0      [点我收藏+]

在编写存储过程时,经常会用到临时表,而且往往会使用临时表与正式表相关联。

当临时表与正式表关联的字段是字符类型的时候,因为临时表创建的字符类型会默认数据库的编码,而正式表的字符编码可能不同,那么这个时候,需要对正式表的该字段加上collate database_default 语句来进行关联,例句:

create table Test
(
Name nvarchar(30),
Age int
)
go

create table #temp
(
Name nvarchar(30),
Class nvarchar(30)
)
go

insert into Test select ‘张三‘,18
union all select ‘李四‘,22
union all select ‘王五‘,20

insert into #temp select ‘张三‘,‘大一‘
union all select ‘李四‘,‘大四‘
union all select ‘王五‘,‘大二‘

select t.*,te.Class from Test t inner join #temp te on t.Name collate database_default=te.Name

drop table #temp
drop table Test

 

 

通过这种方式就能在不同服务器的sqlserver上查询,再也不用担心突然报一个编码不正确的问题

Chinese_PRC_CI_AS and SQL_Latin1_General_CP1_CI_AS类型错误,布布扣,bubuko.com

Chinese_PRC_CI_AS and SQL_Latin1_General_CP1_CI_AS类型错误

原文:http://www.cnblogs.com/Crownsky/p/3747842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!