May 6, 2016 at 3:35 am
So, will we get our point back?
May 6, 2016 at 3:59 am
Interesting question, nice explanation. Might have been worth mentioning the implicit type conversions as well.
Pity about the mistake in the answer. There isn't any implicit case conversion. :laugh:
Tom
May 6, 2016 at 4:04 am
Variable IS NOT converted to nchar. It is the other way arround. The literal is converted to char and thus the value set to variable is dependent on databse collation
Try this to prove:
USE MASTER
GO
CREATE DATABASE unicode_test COLLATE Latin1_General_BIN;
GO
CREATE DATABASE unicode_test_PL COLLATE Polish_CI_AS;
GO
USE unicode_test ;
GO
DECLARE @n CHAR(10);
SET @n = N'abc'; -- a is a special polish character
SELECT UNICODE(@n) AS [unicode];
SELECT @n AS n INTO test;
SELECT * FROM test;
EXEC sp_help 'test';
GO
USE unicode_test_PL;
GO
DECLARE @n CHAR(10);
SET @n = N'abc'; -- a is a special polish character
SELECT UNICODE(@n) AS unicode_pl;
SELECT @n AS n INTO test;
SELECT * FROM test;
EXEC sp_help 'test';
GO
USE MASTER;
GO
DROP DATABASE unicode_test;
GO
DROP DATABASE unicode_test_PL;
May 6, 2016 at 4:29 am
I get result 65 on this. Isn't this correct?:blush:
DECLARE @n CHAR(10);
SET @n = N'Abc';
SELECT UNICODE(@n);
May 6, 2016 at 4:31 am
Will we get our point back? Don't like getting things wrong - esp when they're right?!:hehe:
May 6, 2016 at 4:34 am
Ran the code
Got 65 (as I thought I would)
Got the question wrong??????
Even though N'Abc' is Unicode @n is CHAR, thus the UNICODE command will return the ASCII for A (65).
May 6, 2016 at 5:04 am
tripleAxe (5/6/2016)
upper case / lower case confusion?
SELECT UNICODE(N'a'); ---returns 97
SELECT UNICODE(N'A'); --returns 65
Yep, I want my point please.
May 6, 2016 at 5:08 am
Yes, it does return 65, so the right answer is wrong. Maybe this is an exercise in patience. 😉
May 6, 2016 at 5:46 am
radek.celuch (5/6/2016)
Variable IS NOT converted to nchar. It is the other way arround. The literal is converted to char and thus the value set to variable is dependent on databse collation
Actually conversion happens in both directions in the QotD code.
In the assignment to the variable, the literal is converted to varchar (as demonstrated by your code, or alternatively as is clear from the way implicit conversion is required to operate in order to avoid type violations).
However, in the call to UNICODE the value of the variable is converted to NVARCHAR so that it can act as an argument for UNICODE, as is clearly required to provide a valid argument to the UNICODE function.
So there are implicit conversions in both directions, each where the direction used is the one required by the semantics of T-SQL.
Tom
May 6, 2016 at 6:18 am
Hi,
The correct answer is 65!!!!
May 6, 2016 at 6:29 am
You got it right!
With the words of the poet Shakespeare: Much Ado About Nothing. Steve has done a little typo only.
The result is always 65, even if you run eg. this code:
DECLARE @n CHAR(10);
SET @n = 'Abc';-- not N'Abc'
SELECT UNICODE(@n);
May 6, 2016 at 6:42 am
SADSAC (5/5/2016)
Felix Pamittan (5/5/2016)
Correct answer:
Yes, you can run this code, This returns 97
Explanation:
You can run this code. The CHAR variable is converted to NCHAR and the first character's value returned. An upper case 'A' is 65. Same as ASCII.
I think the answer should be:
Yes, you can run this code, This returns 65
Agree.
"A" is 65 in both ASCII and UNICODE lists.
Agreed...
May 6, 2016 at 6:46 am
I am sorry. Note above I wanted send to Mr. tripleAxe.
May 6, 2016 at 6:49 am
Agreed
May 6, 2016 at 6:52 am
George Vobr (5/6/2016)
I am sorry. Note above I wanted send to Mr. tripleAxe.
Thank you George. 🙂
Viewing 15 posts - 16 through 30 (of 60 total)
You must be logged in to reply to this topic. Login to reply