如果我在托管数据库的远程 sql 服务器上运行相同的 t-sql,我有 t-sql,它在本地 sql 服务器上运行良好,导致错误
我尝试了很多更改,但对我没有任何效果,最后我决定在 Stack Exchange 上写作。
我用来自服务器的脚本创建了我的本地数据库,所以我希望它们不会改变任何数据类型,因为我的查询给了我正确的结果。
这是我的 t-sql
IF OBJECT_ID('tempdb..#TempAppliedData') IS NOT NULL
BEGIN
DROP TABLE #TempAppliedData
END
Create Table #TempAppliedData(
--RecordNo [int],
IdNo1 [nvarchar](50) COLLATE DATABASE_DEFAULT,
--Name [nvarchar](50),
AYear2011 [char](3) COLLATE DATABASE_DEFAULT,
AYear2012 [char](3) COLLATE DATABASE_DEFAULT,
AYear20121 [char](3) COLLATE DATABASE_DEFAULT,
AYear2013 [char](3) COLLATE DATABASE_DEFAULT,
AYear20131 [char](3) COLLATE DATABASE_DEFAULT
);
insert into #TempAppliedData (IdNo1) select distinct IdNo from AppliedData
update #TempAppliedData
set
AYear2011=(select CASE WHEN COUNT(A.Year2011)=0 then 'No' else 'YES' end FROM AppliedData A WHERE Year2011='Yes' and IdNo1=IdNo) ;
update #TempAppliedData
set
AYear2012=(select CASE WHEN COUNT(A.Year2012)=0 then 'No' else 'YES' end FROM AppliedData A WHERE ApplnYear <=20131 AND Year2012='Yes' and IdNo1=IdNo)
update #TempAppliedData
set
AYear20121=(Select CASE WHEN COUNT(A.Year20121)=0 then 'No' else 'YES' end FROM AppliedData A WHERE ApplnYear <=20131 AND Year20121='Yes' and IdNo1=IdNo)
update #TempAppliedData
set
AYear2013=(Select CASE WHEN COUNT(A.Year2013)=0 then 'No' else 'YES' end FROM AppliedData A WHERE ApplnYear <=20131 AND Year2013='Yes' and IdNo1=IdNo)
update #TempAppliedData
set
AYear20131=(Select CASE WHEN COUNT(A.Year20131)=0 then 'No' else 'YES' end FROM AppliedData A WHERE ApplnYear <=20131 AND Year20131='Yes' and IdNo1=IdNo)
Select * from #TempAppliedData;
--select distinct IdNo from AppliedData
其产生错误如下:
Msg 468, Level 16, State 9, Line 28
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CS_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Msg 468, Level 16, State 9, Line 40
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CS_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Msg 468, Level 16, State 9, Line 53
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CS_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Msg 468, Level 16, State 9, Line 66
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CS_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
Msg 468, Level 16, State 9, Line 79
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CS_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.