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 «««123

Printing Lengths Expand / Collapse
Author
Message
Posted Tuesday, December 14, 2010 1:03 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, October 11, 2013 3:27 PM
Points: 127, Visits: 132
Hardy21 (12/14/2010)
Nice question. Learn something new today...


thankss


Rahul
Post #1034228
Posted Tuesday, December 14, 2010 4:10 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:33 AM
Points: 2,468, Visits: 2,346
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

Post #1034277
Posted Friday, December 17, 2010 8:35 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, July 9, 2013 11:12 PM
Points: 1,263, Visits: 1,081
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
Post #1036573
Posted Saturday, December 18, 2010 6:34 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:07 PM
Points: 11,194, Visits: 11,109
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



Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1036876
Posted Saturday, December 18, 2010 3:00 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, June 16, 2014 9:38 AM
Points: 2,163, Visits: 2,189
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


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.)
Post #1036925
Posted Saturday, December 18, 2010 7:38 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:07 PM
Points: 11,194, Visits: 11,109
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #1036941
Posted Thursday, August 11, 2011 12:55 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, July 3, 2014 2:45 AM
Points: 2,531, Visits: 536
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
MCITP:Database Developer 2008
MCTS: SQL Server 2008, Implementation and Maintenance
Post #1158213
Posted Monday, February 27, 2012 10:14 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 10:52 PM
Points: 483, Visits: 244
Thanks for the question on the data types.
Post #1258385
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse