﻿<?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 Peter Kierstead  / VarChar(max)?!? / 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>Sat, 25 May 2013 01:11:33 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>nice to have a clear explanation.Good question</description><pubDate>Fri, 10 Jul 2009 13:04:13 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>--Step 1 Declare @Str VarChar(max);Set @Str=Replicate(cast('*'as varchar(MAX)) ,10000) Print Len(@Str);--Step 2 Declare @Str VarChar(max);Set @Str=Replicate('*' ,10000) Print Len(@Str);----i m hardly got the difference between step 1 and step 2 ..please explain both ????</description><pubDate>Mon, 15 Sep 2008 06:17:53 GMT</pubDate><dc:creator>Bhuvnesh</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>A real good explanation by Simon....Im quiet clear on this one..Thanks Simon:)</description><pubDate>Mon, 18 Aug 2008 00:36:14 GMT</pubDate><dc:creator>Linson.Daniel</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>[quote][b]vlad (8/12/2008)[/b][hr][quote]Nope.  Implicit conversion can be a problem on just about any data type.  Elimination of implicit conversion would be the only way to handle that, and implicit conversion has too many good uses to get rid of it because of people who don't learn how to handle it correctly.- GSquared[/quote]Despite the fact that implicit conversion maybe good or bad,  varchar(max) is a not the same type as varchar(N),  0&amp;lt;=N&amp;lt;=8000 .. something to keep in mind![/quote]Exactly.</description><pubDate>Wed, 13 Aug 2008 08:19:02 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Hi Simon,Thank for the explanation of the question.</description><pubDate>Wed, 13 Aug 2008 07:46:20 GMT</pubDate><dc:creator>bhusank_neuronimbus</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>[quote]Nope.  Implicit conversion can be a problem on just about any data type.  Elimination of implicit conversion would be the only way to handle that, and implicit conversion has too many good uses to get rid of it because of people who don't learn how to handle it correctly.- GSquared[/quote]Despite the fact that implicit conversion maybe good or bad,  varchar(max) is a not the same type as varchar(N),  0&amp;lt;=N&amp;lt;=8000 .. something to keep in mind!</description><pubDate>Tue, 12 Aug 2008 10:51:12 GMT</pubDate><dc:creator>vlad-548036</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>[quote][b]vlad (8/11/2008)[/b][hr]this makes varchar(max) a [b]special[/b] type ... necessitating special handling aka "workaround" for a bug, maybe ??[/quote]Nope.  Implicit conversion can be a problem on just about any data type.  Elimination of implicit conversion would be the only way to handle that, and implicit conversion has too many good uses to get rid of it because of people who don't learn how to handle it correctly.</description><pubDate>Tue, 12 Aug 2008 08:48:50 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Glad to see a clearer explanation from Simon, had a better understanding after that.</description><pubDate>Tue, 12 Aug 2008 02:42:21 GMT</pubDate><dc:creator>Philip Barry</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>this makes varchar(max) a [b]special[/b] type ... necessitating special handling aka "workaround" for a bug, maybe ??</description><pubDate>Mon, 11 Aug 2008 16:07:27 GMT</pubDate><dc:creator>vlad-548036</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Even though the answer was obvious, and even though I had QA open at the time, I went ahead and "Took the Bait". What's 1 lousy point.Good QotD. Learnt sumpin.</description><pubDate>Mon, 11 Aug 2008 14:40:52 GMT</pubDate><dc:creator>Tom Garth</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Nice question. This hasn't burned my yet and this type of question may mean it never does! Thanks.</description><pubDate>Mon, 11 Aug 2008 11:40:16 GMT</pubDate><dc:creator>TDuffy</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Simon, thanks for the explanation.   Implicit conversions involving varchar (max) have bitten me a couple of times already.   Nice question.</description><pubDate>Mon, 11 Aug 2008 08:50:39 GMT</pubDate><dc:creator>Cliff Jones</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>I spotted the implicit conversion and was about to go into the details on it, but then realized Simon had already covered it.Good question.  Understanding implicit conversions is a critical skill for anyone dealing with code.</description><pubDate>Mon, 11 Aug 2008 07:11:48 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Nice... Atif Sheikh</description><pubDate>Mon, 11 Aug 2008 03:54:02 GMT</pubDate><dc:creator>Atif-ullah Sheikh</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Nice question.</description><pubDate>Mon, 11 Aug 2008 03:09:21 GMT</pubDate><dc:creator>Anipaul</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Yup... i got the same results..</description><pubDate>Mon, 11 Aug 2008 00:58:44 GMT</pubDate><dc:creator>ChiragNS</dc:creator></item><item><title>RE: VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>I thought the explanation was really lacking something ... like explainingThe REPLICATE function only returns 8000 characters (defaults to VARCHAR(8000)) if the character value to be replicated isn't explicitly CAST as VARCHAR(MAX). As both REPLICATE statements are internally CAST as VARCHAR(8000) fields, the concatenation of the two VARCHAR(8000) fields yields another VARCHAR(8000) field [b]before[/b] assigning the value to the @str field, hence the results is 8000, not 16000 as you might expect.To try and make that clearer ...[code]DECLARE @Str VARCHAR(MAX);-- The Example from the QOTDSET @Str=REPLICATE('*',10000) + REPLICATE('*',10000);PRINT LEN(@Str);-- Explicitly CAST the Replicated character as type VARCHAR(MAX)SET @Str=REPLICATE(CAST('*' AS VARCHAR(MAX)),10000) + REPLICATE(CAST('*' AS VARCHAR(MAX)),10000);PRINT LEN(@Str);-- Explicitly CAST the results from REPLICATE statements as VARCHAR(MAX), without casting the Replicated character as VARCHAR(MAX)SET @Str=CAST(REPLICATE('*',10000) AS VARCHAR(MAX)) + CAST(REPLICATE('*',10000) AS VARCHAR(MAX));PRINT LEN(@Str);[/code]Gives the results:[code]80002000016000[/code]</description><pubDate>Sun, 10 Aug 2008 20:58:08 GMT</pubDate><dc:creator>Simon Facer</dc:creator></item><item><title>VarChar(max)?!?</title><link>http://www.sqlservercentral.com/Forums/Topic549830-1321-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/TSQL/63596/"&gt;VarChar(max)?!?&lt;/A&gt;[/B]</description><pubDate>Sat, 09 Aug 2008 23:38:19 GMT</pubDate><dc:creator>Peter E. Kierstead</dc:creator></item></channel></rss>