选择查询中的排序规则冲突

时间:2019-05-30 11:12:30

标签: sql sql-server database

要在SQL的Select语句中设置排序规则。

我在下面的SQL查询中遇到错误:
无法通过等于操作解决“ SQL_Latin1_General_CP1_CI_AS”和“ Latin1_General_CI_AI”之间的排序规则冲突。

我有为连接设置排序规则的想法,在这种情况下,我没有想法。

下面是我要为其设置 COLLATE SQL_Latin1_General_CP1_CI_AI 的SQL查询,

SET @ColumnNames_CSV_Responses_Smoker_Retail = ' ';
SELECT @ColumnNames_CSV_Responses_Smoker_Retail = COALESCE(@ColumnNames_CSV_Responses_Smoker_Retail, '') +
                                                  CASE WHEN QuestionType IN (2, 3, 4)
                                                        AND EXISTS (SELECT *
                                                                    FROM Optiontable
                                                                    WHERE Option_Code = '1001'
                                                                      AND Optiontable.Question_ID = Question.QuestionID) THEN 'dbo.ReplaceBrandIDWithCode(''' + CAST(QuestionID AS varchar) + ''',[' + CAST(QuestionID AS varchar) + ']) AS [' + CAST(QuestionID AS varchar) + '],'
                                                       WHEN QuestionType IN (3) THEN 'REPLACE(RTRIM(LTRIM([' + CAST(QuestionID AS varchar) + '])),'' '', ''#'') AS [' + CAST(QuestionID AS varchar) + '],'
                                                       WHEN QuestionType IN (4) THEN 'REPLACE(REPLACE(SUBSTRING(RTRIM(LTRIM([' + CAST(QuestionID AS varchar) + '])),1, LEN(RTRIM(LTRIM([' + CAST(QuestionID AS varchar) + ']))) - 1),''^'', ''#''),'','','''') AS [' + CAST(QuestionID AS varchar) + '],'
                                                       ELSE 'REPLACE(RTRIM(LTRIM([' + CAST(QuestionID AS varchar) + '])),'','', '' '') AS [' + CAST(QuestionID AS varchar) + '],'
                                                  END
FROM Question
WHERE CAST(QuestionID AS varchar)IN (SELECT COLUMN_NAME
                                     FROM INFORMATION_SCHEMA.COLUMNS
                                     WHERE TABLE_NAME = @Table_Name)
ORDER BY QuestionSeqNumber;

感谢您的帮助。

0 个答案:

没有答案