September 23, 2012 at 6:33 am
Hi Friends,
I am getting unexpected result:Please Explain deeply.
SELECT CAST(643 AS VARCHAR(1))
select Cast(45 as char(1))
Result:
*
why i am getting result as * .what does it mean? what is the logic behind unexpected result..
please send me answer as soon as possible....
Thanks!!
Regards,
Shubham Saxena
September 23, 2012 at 7:03 am
This is documented in the Truncating and Rounding Results section of CAST and CONVERT in Books Online. The * means 'Result length too short to display'. This odd behaviour is maintained for backward compatibility with old versions of SQL Server. The more modern types nchar and nvarchar return an error instead:
SELECT CAST(643 AS nvarchar(1));
SELECT CAST(45 as nchar(1));
[font="Courier New"]Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type nvarchar.[/font]
September 23, 2012 at 7:12 am
Expanding upon SQL Kiwi reply - read this
http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx
Scroll down to about the middle of the page to see the explanation.
September 23, 2012 at 7:42 am
bitbucket-25253 (9/23/2012)
Scroll down to about the middle of the page to see the explanation.
That's just the SQL Server 2000 version of the same Books Online link to CAST and CONVERT I have in my reply 🙂
September 23, 2012 at 8:16 am
Hmmm... deja vu
http://www.sqlservercentral.com/Forums/FindPost1362083.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 23, 2012 at 8:52 am
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply