|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, June 11, 2013 3:52 AM
Points: 127,
Visits: 123
|
|
Hardy21 (12/14/2010) Nice question. Learn something new today...
thankss
Rahul
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 7:18 AM
Points: 1,996,
Visits: 1,864
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 28, 2013 1:34 AM
Points: 1,263,
Visits: 1,080
|
|
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
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 10:48 AM
Points: 10,990,
Visits: 10,578
|
|
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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 9:45 AM
Points: 2,163,
Visits: 2,151
|
|
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.)
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 10:48 AM
Points: 10,990,
Visits: 10,578
|
|
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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 5:31 AM
Points: 2,226,
Visits: 438
|
|
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
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 8:52 AM
Points: 469,
Visits: 199
|
|
| Thanks for the question on the data types.
|
|
|
|