SQL 可以二次整理吗?

SQL Is it possible to collate twice?

你好我创建了以下脚本,我 运行 遇到的问题是我查询的两个 table 的排序不同,我试图将数据插入第三个 table,但由于 tables 的整理,我不能这样做,由于数据库和依赖它的程序的限制,我也无法整理 tables 本身。 那么是否可以正确整理呢?

Error:    Msg 468, Level 16, State 9, Line 69
    Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation.





        --Create Table #tmp2(FK_clientids varchar(50))
        --Create table #tmp (phonenums varchar(50))
        --Create table #tmp3 (phonenum varchar(50),fk_applicationid_solref varchar(50),calldata varchar(50),sourcetable varchar(50))
        Delete from #tmp2
        Delete from #tmp
        Use DATABASE2
        INSERT INTO #tmp2
        SELECT fk_clientid
        FROM DM_ClientApplicants
        where FK_ApplicationID in (39591,
        39594,
        39598,
        39596,
        39600,
        39601,
        39603,
        39609,
        39613,
        39585,
        39560)

        Use DATABASE2
        INSERT INTO #tmp
        Select phonenum2 from DM_PhoneNumbers
        where FK_ApplicationID in 
        (
           Select FK_clientIDs from #tmp2
        )
        INSERT INTO #tmp
        Select PhoneNum1 from DM_PhoneNumbers
        where FK_ApplicationID in 
        (
           Select FK_clientIDs from #tmp2
        )
        INSERT INTO #tmp
        Select PhoneNum2 from DM_PhoneNumbers
        where FK_ApplicationID in 
        (
           Select FK_clientIDs from #tmp2
        )

        INSERT INTO #tmp
        Select PhoneNum3 from DM_PhoneNumbers
        where FK_ApplicationID in 
        (
           Select FK_clientIDs from #tmp2
        )
        INSERT INTO #tmp
        Select Partnerphonehome from DM_PhoneNumbers
        where FK_ApplicationID in 
        (
           Select FK_clientIDs from #tmp2
        )
        INSERT INTO #tmp
        Select Partnerphonemobile from DM_PhoneNumbers
        where FK_ApplicationID in 
        (
           Select FK_clientIDs from #tmp2
        )
        INSERT INTO #tmp
        Select Partnerphonework from DM_PhoneNumbers
        where FK_ApplicationID in 
        (
           Select FK_clientIDs from #tmp2
        )
        Use DATABASE1
        insert into #tmp3

Select sourcetable,CallData,PhoneNum,P.FK_ApplicationID from Dial D

        join DATABASE2.dbo.DM_PhoneNumbers P on PhoneNum = PhoneNum1
        join DATABASE2.dbo.DM_Sol s on S.FK_ApplicationID = P.FK_ApplicationID
       Collate Latin_general_CI_AS

        where PhoneNum in
        (
        Select phonenums from #tmp
        )

您可以将整理子句用作 ON 子句的一部分。从您发布的代码中,我无法分辨哪个是哪个,但它会是这样的:

    join DATABASE2.dbo.DM_PhoneNumbers P 
            on PhoneNum collate SQL_Latin1_General_CP1_CI_AS  = PhoneNum1 

重点是您需要使用排序规则来修改连接列之一的排序规则以匹配另一列。