﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Rahul Kr. Ghosh  / Printing Lengths / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 21:44:34 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Thanks for the question on the data types.</description><pubDate>Mon, 27 Feb 2012 10:14:11 GMT</pubDate><dc:creator>zymos</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>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.</description><pubDate>Thu, 11 Aug 2011 00:55:46 GMT</pubDate><dc:creator>hakan.winther</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>[quote][b]UMG Developer (12/18/2010)[/b][hr]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.)[/quote]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.</description><pubDate>Sat, 18 Dec 2010 19:38:46 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>[quote][b]SQLkiwi (12/18/2010)[/b][hr]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[/quote]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.)</description><pubDate>Sat, 18 Dec 2010 15:00:42 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>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</description><pubDate>Sat, 18 Dec 2010 06:34:52 GMT</pubDate><dc:creator>Paul White</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Thanks for the question, Rahul.But personally I find the explanation somewhat confusing, specifically the last paragraph where it reads:[quote]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[/quote]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 [b]long[/b] to fit into a column implicitely set to varchar(1) = by not specifying the length in the variable declarartion.Regards,Michael</description><pubDate>Fri, 17 Dec 2010 08:35:28 GMT</pubDate><dc:creator>michael.kaufmann</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>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 &amp;gt; 10.Endless loop</description><pubDate>Tue, 14 Dec 2010 04:10:09 GMT</pubDate><dc:creator>Carlo Romagnano</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>[quote][b]Hardy21 (12/14/2010)[/b][hr]Nice question. Learn something new today...[/quote]thankss</description><pubDate>Tue, 14 Dec 2010 01:03:15 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Nice question. Learn something new today...</description><pubDate>Tue, 14 Dec 2010 00:54:07 GMT</pubDate><dc:creator>Hardy21</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>good one, thanks Rahul...:-)[code="sql"]declare @myvariable as varchar, @len1 varchar, @len2 varcharset @myvariable = 'hi hello how are you'set @len1 = (select datalength(cast(@myvariable as char)))print @len1set @len1 = (select datalength(cast(@myvariable as varchar)))print @len1set @len2 = (select datalength(convert(char, @myvariable)))print @len2set @len2 = (select datalength(convert(varchar, @myvariable)))print @len2[/code]The above code generates output as[code="plain"]*1*1[/code]difference of char, varchar datatypes...:-)</description><pubDate>Mon, 13 Dec 2010 23:12:38 GMT</pubDate><dc:creator>ziangij</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Thanks for the question.</description><pubDate>Mon, 13 Dec 2010 18:11:03 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Thanks for the interesting question. Though I hope questions like this wouldn't be necessary, and that people would always specify a length on variables to keep themselves out of trouble.</description><pubDate>Mon, 13 Dec 2010 13:42:52 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>[quote][b]Rahul The Dba (12/13/2010)[/b][hr]thanksn i promise i will keep ur words in mind, nxt time i post some questions..[/quote]Rahul,We are not able to tell who these comments are for if you do not post a quoted reply like this one.:cool: Or at the very least include thier name in the post.--------I have.Who has ever been called a "Top Poster"? </description><pubDate>Mon, 13 Dec 2010 12:06:14 GMT</pubDate><dc:creator>SanDroid</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Once again we learn that you should never rely on default datatype precision, but specify it yourself!</description><pubDate>Mon, 13 Dec 2010 10:10:25 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>thanksn i promise i will keep ur words in mind, nxt time i post some questions..</description><pubDate>Mon, 13 Dec 2010 09:11:12 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>that's great ur welcome</description><pubDate>Mon, 13 Dec 2010 09:08:57 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>thanks</description><pubDate>Mon, 13 Dec 2010 09:07:14 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>thanks</description><pubDate>Mon, 13 Dec 2010 09:06:00 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Good question. Taught me something I need to learn.Thanks,webrunner</description><pubDate>Mon, 13 Dec 2010 07:20:24 GMT</pubDate><dc:creator>webrunner</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Inconsistent behavior of SQL Server on the default length.  I learned something today.  Thanks.</description><pubDate>Mon, 13 Dec 2010 07:00:21 GMT</pubDate><dc:creator>Daniel Bowlin</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Nice question, although I believe I've seen similar around here (but hey, it can't hurt to refresh things from time to time).Some reference links would have been nice for those who would've wanted to read up on the subject.</description><pubDate>Mon, 13 Dec 2010 05:38:16 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Thanks a lot for your good question!;-) and i did it right! :w00t:</description><pubDate>Mon, 13 Dec 2010 04:12:48 GMT</pubDate><dc:creator>binli0114</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Thanks for a good question - I hadn't realised there would be a scope problem in this instance so I learnt something new today :-)</description><pubDate>Mon, 13 Dec 2010 04:11:00 GMT</pubDate><dc:creator>jts_2003</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Thanks..</description><pubDate>Sun, 12 Dec 2010 23:49:34 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Good question.  Not sure how I managed to get it wrong, because it's prety straightforward.</description><pubDate>Sun, 12 Dec 2010 19:22:34 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>[quote][b]Rahul The Dba (12/12/2010)[/b][hr]Hi,All my drear readers hope you will be able to learn a trick about varchar and char datatypes in SQL.Thanks for viewing it.....[/quote]I did and thanks for posting ... was/is a good question</description><pubDate>Sun, 12 Dec 2010 17:05:38 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>RE: Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Hi,All my drear readers hope you will be able to learn a trick about varchar and char datatypes in SQL.Thanks for viewing it.....</description><pubDate>Sun, 12 Dec 2010 04:00:25 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item><item><title>Printing Lengths</title><link>http://www.sqlservercentral.com/Forums/Topic1033369-2866-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/71484/"&gt;Printing Lengths&lt;/A&gt;[/B]</description><pubDate>Sat, 11 Dec 2010 13:02:51 GMT</pubDate><dc:creator>Rahul The Dba</dc:creator></item></channel></rss>