我有一个SQL查询来使用临时表更新数据库表中的值:
Create Table #tmpTbl (Value varchar(30))
insert into #tmpTbl values ('Value1'),('Value2'),('Value3'),('Value4')
Declare @Var2 varchar (250)
Set @Var2 = 'Variable2'
Update DB_Table
Set Var2 = @Var2
where Var1 in (Select * from #tmpTbl )
drop table #tmpTbl
我收到了错误
Cannot resolve the collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
我尝试在collate Latin1_General_CI_AS
语句的末尾添加create table
,但错误仍然存在。
我该如何解决这个问题?或者有更好的方法来实现我想要做的事情吗?
答案 0 :(得分:2)
尝试这样的事情:
UPDATE DB_TABLE
SET VAR2 = @Var2
WHERE VAR1 COLLATE DATABASE_DEFAULT IN (SELECT VALUE COLLATE DATABASE_DEFAULT
FROM #TMPTBL)