SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Unexpected Result of Select Statement: Shubham Saxena


Unexpected Result of Select Statement: Shubham Saxena

Author
Message
shubham.saxena67
shubham.saxena67
SSC-Enthusiastic
SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)SSC-Enthusiastic (136 reputation)

Group: General Forum Members
Points: 136 Visits: 228
Hi Friends,

I am getting unexpected resultTonguelease 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
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15546 Visits: 11355
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));



Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type nvarchar.




Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7777 Visits: 25280
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.

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15546 Visits: 11355
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 :-)



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
GilaMonster
GilaMonster
SSC Guru
SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)SSC Guru (86K reputation)

Group: General Forum Members
Points: 86526 Visits: 45242
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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Dave Ballantyne
Dave Ballantyne
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2874 Visits: 8370
http://blog.sqlauthority.com/2012/09/20/sql-server-2-t-sql-puzzles-and-win-usd-50-worth-amazon-gift-card-and-25-other-prizes/

Quick, $50 for the correct answer Smile



Clear Sky SQL
My Blog
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15546 Visits: 11355

Sigh. I suggest these for part 2:


SELECT COUNT(*)
SELECT DAY('')
SELECT DB_ID() -- in master database only





Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search