Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inexplicable Behaviour of Select

Author  Topic 

PoojaJ
Starting Member

10 Posts

Posted - 2007-04-13 : 02:27:38
Hi

Just tried to Run the Following statement in Query Analyzer
Select convert(varchar(9),convert(integer,1234567890))

The Output was an * (asterisk)
Can Some one Explain Y??

Thanks in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-13 : 02:34:58
You expected that only the first 9 digits would be converted, right?
NO! The answer is readable in Books Online.

First I opened Books Online and typed CONVERT in the search box. Then I scrolled down to see what information there is.
quote:
Truncating and Rounding Results

When you convert character or binary expressions (char, nchar, nvarchar, varchar, binary, or varbinary) to an expression of a different data type, data can be truncated, only partially displayed, or an error is returned because the result is too short to display. Conversions to char, varchar, nchar, nvarchar, binary, and varbinary are truncated, except for the conversions shown in the following table.
From data type                                       To data type  Result  
--------------------------------------------------- ------------ ------
int, smallint, or tinyint char *
varchar *
nchar E
nvarchar E

money, smallmoney, numeric, decimal, float, or real char E
varchar E
nchar E
nvarchar E


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-13 : 03:27:19
I expect Error rather than *

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

PoojaJ
Starting Member

10 Posts

Posted - 2007-04-13 : 03:34:00
Thanks a lot for ur Reply
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-13 : 03:34:44
quote:
Originally posted by madhivanan

I expect Error rather than *

Madhivanan

Failing to plan is Planning to fail


This behavior is by design


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-13 : 03:41:38
May be bad design

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-13 : 04:29:07
May be asterisk is chosen because it is commonly used wild-card character which used to represent one or more characters or may be because it resembles shape of bug

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-13 : 04:35:02
quote:
because it resembles shape of bug

This sounds like a more likely reason


KH

Go to Top of Page
   

- Advertisement -