无法解决ORDER BY中第1列的排序规则冲突

时间:2015-03-23 15:28:21

标签: sql sql-server-2008 sqlexception

当我执行查询时,我得到了这个SQL异常:

Cannot resolve collation conflict for column 1 in ORDER BY statement

SELECT     ISNULL(ROW_NUMBER() OVER (ORDER BY ARTICLE), 0) AS NBR, DATE, ARTICLE, TYPE, QTE_FRN, QTE_DEPOT, QTE_PAT, QTE_MOUV, CHAMP_STOCK, 
    DEPOT
    FROM         (SELECT     dbo.V_STOCK.DATE, dbo.V_STOCK.ARTICLE, dbo.V_STOCK.TYPE, CASE WHEN TYPE IN (100, 101, 103, 200) THEN QTE WHEN TYPE IN (102, 204) 
                                                  THEN - 1 * QTE END AS QTE_FRN, CASE WHEN TYPE IN (201, 203) THEN QTE WHEN TYPE = 202 THEN - 1 * QTE END AS QTE_DEPOT, 
                                                  CASE WHEN TYPE IN (300, 301, 303) THEN QTE WHEN TYPE = 302 THEN - 1 * QTE END AS QTE_PAT, CASE WHEN TYPE IN (402, 502, 602) 
                                                  THEN QTE WHEN TYPE IN (401, 501, 601) THEN - 1 * QTE END AS QTE_MOUV, dbo.NXT_PH_CHOIX_MODULE.CHAMP_STOCK, dbo.V_STOCK.DEPOT
                           FROM          dbo.NXT_PH_CHOIX_MODULE RIGHT OUTER JOIN
                                                  dbo.V_STOCK ON dbo.NXT_PH_CHOIX_MODULE.TYPE_CHOIX = dbo.V_STOCK.TYPE
                           UNION ALL
                           SELECT     NextCare.dbo.V_STOCK_PHARMACIE.DATE, NextCare.dbo.V_STOCK_PHARMACIE.ARTICLE, NextCare.dbo.V_STOCK_PHARMACIE.TYPE, 
                                                 NextCare.dbo.V_STOCK_PHARMACIE.QTE_FRN, NextCare.dbo.V_STOCK_PHARMACIE.QTE_DEPOT, NextCare.dbo.V_STOCK_PHARMACIE.QTE_PAT, 
                                                 NextCare.dbo.V_STOCK_PHARMACIE.QTE_MOUV, NXT_PH_CHOIX_MODULE_1.CHAMP_STOCK, NextCare.dbo.V_STOCK_PHARMACIE.DEPOT
                           FROM         dbo.NXT_PH_CHOIX_MODULE AS NXT_PH_CHOIX_MODULE_1 RIGHT OUTER JOIN
                                                 NextCare.dbo.V_STOCK_PHARMACIE ON NXT_PH_CHOIX_MODULE_1.TYPE_CHOIX = NextCare.dbo.V_STOCK_PHARMACIE.TYPE) AS VIEW_S

1 个答案:

答案 0 :(得分:0)

您的文章组成的字符串(我猜他们是dbo.V_STOCK.ARTICLE和NextCare.dbo.V_STOCK_PHARMACIE.ARTICLE)似乎是不同的排序规则。尝试将COLLATE DATABASE_DEFAULT添加到脚本中的字符串字段:dbo.V_STOCK.ARTICLE COLLATE DATABASE_DEFAULTNextCare.dbo.V_STOCK_PHARMACIE.ARTICLE COLLATE DATABASE_DEFAULT。 有关callatoin的更多信息,请参阅: https://msdn.microsoft.com/en-us/library/ms184391.aspxCannot resolve collation conflict for column 4 in SELECT statement