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


Printing Lengths


Printing Lengths

Author
Message
Rahul The Dba
Rahul The Dba
SSC Veteran
SSC Veteran (263 reputation)SSC Veteran (263 reputation)SSC Veteran (263 reputation)SSC Veteran (263 reputation)SSC Veteran (263 reputation)SSC Veteran (263 reputation)SSC Veteran (263 reputation)SSC Veteran (263 reputation)

Group: General Forum Members
Points: 263 Visits: 133
Hardy21 (12/14/2010)
Nice question. Learn something new today...


thankss

Rahul:-P
Carlo Romagnano
Carlo Romagnano
SSCertifiable
SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)

Group: General Forum Members
Points: 7668 Visits: 3401
This is an old kind of COBOL bug:
using bad datatype to hold integer:

01 IDX PIC 9.

PERFORM LBL VARYING IDX BY 1 UNTIL IDX > 10.

Endless loop

I run on tuttopodismo
michael.kaufmann
michael.kaufmann
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1595 Visits: 1082
Thanks for the question, Rahul.

But personally I find the explanation somewhat confusing, specifically the last paragraph where it reads:

It is '*' because when we convert character or binary expressions 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. * means the result length too short to display


In regards to the default length when n is undefined, it doesn't make a difference whether you use CAST or CONVERT.
@length1 prints 1 because no conversion is carried out (varchar = varchar).
@length2 prints * because the result (30, due to the conversion from varchar to char) actually is too long to fit into a column implicitely set to varchar(1) = by not specifying the length in the variable declarartion.

Regards,
Michael
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)

Group: General Forum Members
Points: 37004 Visits: 11361
I took a stab at 1,30. So it was 1,*. Ha, very good. I'll have forgotten this again in half an hour, and I still won't care :-D



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
UMG Developer
UMG Developer
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4164 Visits: 2204
SQLkiwi (12/18/2010)
I took a stab at 1,30. So it was 1,*. Ha, very good. I'll have forgotten this again in half an hour, and I still won't care :-D


Will you have forgotten it again because you always specify the length and this isn't an issue? (Unless of course you are working on code written by somebody that doesn't.)
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)SSC-Dedicated (37K reputation)

Group: General Forum Members
Points: 37004 Visits: 11361
UMG Developer (12/18/2010)
Will you have forgotten it again because you always specify the length and this isn't an issue? (Unless of course you are working on code written by somebody that doesn't.)

Yes. If I do have to work on code written by someone that thought it was clever to omit lengths, I always have to look it up to be sure.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
hakan.winther
hakan.winther
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3349 Visits: 612
Thanks for the question! Learned something today. I knew about the default length for char/varchar, but not the convert issue. An important sample to show why you shouldn't omit default values or on mandatory statements.

/Håkan Winther
MCITPBigGrinatabase Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
MCSE: Data Platform
zymos
zymos
Right there with Babe
Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)Right there with Babe (758 reputation)

Group: General Forum Members
Points: 758 Visits: 263
Thanks for the question on the data types.
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