Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Unexpected Result of Select Statement: Shubham Saxena Expand / Collapse
Author
Message
Posted Sunday, September 23, 2012 6:33 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, July 21, 2014 11:26 PM
Points: 87, Visits: 217
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
Post #1363222
Posted Sunday, September 23, 2012 7:03 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: 2 days ago @ 7:53 PM
Points: 9,928, Visits: 11,194
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1363226
Posted Sunday, September 23, 2012 7:12 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, November 6, 2014 1:00 PM
Points: 5,333, Visits: 25,277
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
Post #1363227
Posted Sunday, September 23, 2012 7:42 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: 2 days ago @ 7:53 PM
Points: 9,928, Visits: 11,194
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1363228
Posted Sunday, September 23, 2012 8:16 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 10:25 AM
Points: 40,385, Visits: 36,827
Hmmm... deja vu

http://www.sqlservercentral.com/Forums/FindPost1362083.aspx



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1363231
Posted Sunday, September 23, 2012 8:28 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 2:06 AM
Points: 1,768, Visits: 8,318
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 :)




Clear Sky SQL
My Blog
Kent user group
Post #1363232
Posted Sunday, September 23, 2012 8:52 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: 2 days ago @ 7:53 PM
Points: 9,928, Visits: 11,194

Sigh. I suggest these for part 2:

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





Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1363234
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse