|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 11:14 AM
Points: 7,087,
Visits: 7,141
|
|
Robert-378556 (12/3/2012)
SQL Kiwi (12/3/2012)
Jaroslav Pfauser (12/3/2012) (0 row(s) affected) SQL2008 (64-bit) SP2It seems you wrote a test script that did not cover the full range of possibilities. Include CHAR(198) and CHAR(230) in your test. (2 row(s) affected) Doesn't the test sql provided in answer already do that? On my server it returns 0 rows, so it appears like some other things affect this. Maybe default collation. Probably. Yes, the default collation. The test sql in the answer works where the default collation is one of the Latin1_General set, but for some other collations it doesn't. I should have specified a default collation for the context of the code as part of the answer. What 8-bit character char(I) delivers depends on the default collation for the context in which char is called, so that whether ascii(char(I)) = I (I a non-negative integer less than 256) depends on what I is and what the default collation is. Personally I think that's unfortunate, but that's how char operates.
Tom Que conclure à la fin de tous mes longs propos? C'est que les préjugés sont la raison des sots. (Voltaire, 1756)
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 10:33 AM
Points: 10,989,
Visits: 10,529
|
|
Robert-378556 (12/3/2012)
SQL Kiwi (12/3/2012)
Jaroslav Pfauser (12/3/2012) (0 row(s) affected) SQL2008 (64-bit) SP2It seems you wrote a test script that did not cover the full range of possibilities. Include CHAR(198) and CHAR(230) in your test. (2 row(s) affected) Doesn't the test sql provided in answer already do that? On my server it returns 0 rows, so it appears like some other things affect this. Maybe default collation. Probably. Oh my apologies - I didn't even read the explanation today. Of course the question should have used a SQL collation, not a Windows one that takes account of Windows language settings. Using a SQL collation would ensure that everyone used the same code page and displayed the same characters (well, almost):
SELECT CHAR(198) COLLATE SQL_Czech_CP1250_CI_AS, CHAR(230) COLLATE SQL_Czech_CP1250_CI_AS; SELECT CHAR(198) COLLATE SQL_Latin1_General_CP1_CI_AI, CHAR(230) COLLATE SQL_Latin1_General_CP1_CI_AI;
╔═══╦═══╗ ║ A ║ a ║ ╠═══╬═══╣ ║ Æ ║ æ ║ ╚═══╩═══╝
Paul White SQL Server MVP SQLblog.com @SQL_Kiwi
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 10:31 AM
Points: 3,454,
Visits: 2,529
|
|
Bex (12/3/2012) I'll hold my hand up and say I got this right by means of a lucky guess.
Very interesting question and excellent, full answer.
Thanks, Tom!
Bex +1
I wish I could say 'educated'... but it really was 'lucky.'
Thanks, Tom!
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Thursday, May 02, 2013 3:45 PM
Points: 3,748,
Visits: 928
|
|
I set up a test script and ran it, and to my surprise got the right answer based on the script outcome. I was surprised of the results.
Excellent question, Tom!! Keep them coming! Saludos,
"El" Jerry.
"A watt of Ottawa" - Gerardo Galvan
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 6:47 AM
Points: 1,565,
Visits: 769
|
|
*blush* Being wrong is teaching me even more about collations. I'm also seeing another possible advantage to unicode. Switching to unicode, it looks like NCHAR(198) and NCHAR(230) returns the same values (Æ, æ) in Latin and Czech collations. I assume it'll be the same in all collations...
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 2:15 PM
Points: 471,
Visits: 485
|
|
I read this question completely different and ended up getting it correct anyway. I guessed two because of '[' and ']'....
I'll take it!
Aigle de Guerre!
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Thursday, December 06, 2012 4:37 PM
Points: 56,
Visits: 60
|
|
I've never use Collate and don't know what it does. I figured the answer would be 5. Like 5 letters excluding the upper case, would leave the 5 lower case. Not seeing that in the answer, I chose more than 3. Based on some of the comments, I could, technically, be considered correct.
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 10:27 AM
Points: 690,
Visits: 1,100
|
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 7:39 AM
Points: 9,370,
Visits: 6,467
|
|
|
|
|