Monday, February 20, 2012

PIVOT is not case-sensitive

Hi there,

I am using a PIVOT to count the number of chunk for each block type:
ex.:
block_type, chunk
a, <data>
a, <data>
b, <data> ...

My problem is that the block_type is case-sensitive, 'a' should not be counted as a 'A'.
How can I take the case in consideration?

I've tried to plug a COLLATE SQL_Latin1_General_CP1_CS_AS statement but it doesn't seem to be supported... Something like:
SELECT *
FROM recv.test_Blocks
PIVOT (
COUNT(chunk)
FOR block_type COLLATE SQL_Latin1_General_CP1_CS_AS
IN ([9.], a, B, h, q)
) AS pvt

Also something like:
IN (a, A)
returns an error: The column 'A' was specified multiple times for 'pvt'.

Thanks

Collation of identifiers depends on the level at which there are defined. For tables and column names, the collation of the database is used. So if you are trying this on a database with case-insensitive collation it is expected behavior. You need to change the collation of the database to have column names that differ only by case. See Books Online topic on "Identifier Collation" for more details.

No comments:

Post a Comment