ITADN

Example with no-collation is misleading and incorrect in Fabric DW

#9764Closedjovanpop-msft 创建于 2024-04-22
Pri3
J
jovanpop-msftcommented
Source: https://github.com/MicrosoftDocs/sql-docs/blob/live/docs/t-sql/statements/collation-precedence-transact-sql.md There is one misleading issue in [Collation Precedence - SQL Server | Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/statements/collation-precedence-transact-sql?view=sql-server-ver16#no-collation-labels) doc. In the examples, the following code should not return error if GreekCol and Latingol have different collations: ```sql SELECT (CASE WHEN id > 10 THEN GreekCol ELSE LatinCol END) COLLATE Latin1_General_CI_AS FROM TestTab; ``` However, this is true only if both columns are NVARCHAR. If we replace the NVARCHAR column type with VARCHAR and even if we put UTF8 collation on VARCHAR, the expression will fail. This is a big problem for FabricDw where `nvarchar` is not supported and all columns are `varchar`. A reader might try to do this in fabric DW and since they cannot create `nvarchar` columns they would believe that FabricDw doesn't work. We need to clarify that this is applicable only to NVARCHAR, and the example is not applicable to Fabric DW. The full repro is below: ```sql DROP TABLE IF EXISTS TestTab GO CREATE TABLE TestTab ( id int, GreekCol varchar(10) collate greek_ci_as, LatinCol varchar(10) collate latin1_general_cs_as, NGreekCol nvarchar(10) collate greek_ci_as, NLatinCol nvarchar(10) collate latin1_general_cs_as, U8GreekCol varchar(10) collate Greek_100_CI_AS_SC_UTF8, U8LatinCol varchar(10) collate Latin1_General_100_CI_AS_SC_UTF8 ) INSERT TestTab VALUES (1, N'A', N'a', N'A', N'a', N'A', N'a'); GO --NVARCHAR SELECT (CASE WHEN id > 10 THEN NGreekCol ELSE NLatinCol END) COLLATE Latin1_General_CI_AS FROM TestTab; -- Works fine like in documentation. --VARCHAR non-UTF8 SELECT (CASE WHEN id > 10 THEN GreekCol ELSE LatinCol END) COLLATE Latin1_General_CI_AS FROM TestTab; --Msg 457, Level 16, State 1, Line 39 --Implicit conversion of varchar value to varchar cannot be performed because the collation of the value is unresolved --due to a collation conflict between "Latin1_General_CS_AS" and "Greek_CI_AS" in CASE operator. --VARCHAR UTF8 SELECT (CASE WHEN id > 10 THEN U8GreekCol ELSE U8LatinCol END) COLLATE Latin1_General_CI_AS FROM TestTab; --Msg 457, Level 16, State 1, Line 48 --Implicit conversion of varchar value to varchar cannot be performed because the collation of the value is unresolved --due to a collation conflict between "Latin1_General_100_CI_AS_SC_UTF8" and "Greek_100_CI_AS_SC_UTF8" in CASE operator. ```
关闭于 2024-04-23 2 条评论