November 6, 2008 at 8:42 am
GĀ² (11/6/2008)
It was my understanding that varchar(max) was meant to be a replacement to the text data type because of the issue that this question raises as well as other like:Being able to use varchar(max) as a local variable (can't with text)
Being able to use most string functions with it
It can still hold 2Gb of data like text can, so what would this break?
Please correct me if I'm wrong. These discussions are great!
Greg
Yes, all of the above is true. That is why I have changed my usage when we dropped SQL Server 2000 support. As to breakage, the application could be using READTEXT, WRITETEXT, UPDATETEXT, TEXTPTR, etc. See the BOL for details.
November 6, 2008 at 8:52 am
JohnG (11/6/2008)
GĀ² (11/6/2008)
It was my understanding that varchar(max) was meant to be a replacement to the text data type because of the issue that this question raises as well as other like:Being able to use varchar(max) as a local variable (can't with text)
Being able to use most string functions with it
It can still hold 2Gb of data like text can, so what would this break?
Please correct me if I'm wrong. These discussions are great!
Greg
Yes, all of the above is true. That is why I have changed my usage when we dropped SQL Server 2000 support. As to breakage, the application could be using READTEXT, WRITETEXT, UPDATETEXT, TEXTPTR, etc. See the BOL for details.
That's a good point. I hadn't thought of the text specific functions.
Thanks,
Greg
November 6, 2008 at 8:58 am
GĀ² (11/6/2008)
That's a good point. I hadn't thought of the text specific functions.
Thanks,
Greg
Now you know why just performing an "ALTER TABLE" to change the data type could not be considered a "workaround" to the specific query problem. The entire application could fail.
November 6, 2008 at 8:58 am
DOCTOR FRANKENSTEIN
OPEN UP !
November 6, 2008 at 9:05 am
Not mentioned as an answer, but here is a workaround using varchar(max) (or nvarchar(max)); build views over the two tables and cast the text/ntext column as a varchar(max)/nvarchar(max) datatype in the select statement.
There is your workaround, and it doesn't affect the underlying table or procedures that work with the text/ntext column.
November 6, 2008 at 9:10 am
Now, this is a workaround I can live with. Good idea.
But I am still miffed at not having my points. (grin).
November 6, 2008 at 9:18 am
Several people have complained that changing the text column to varchar(max) is bad because you are changing the data, which is right, so I'd just do the conversion in line..select id, convert(varchar(max),somestuff) as 'somestuff' from tableA
union
select id, convert(varchar(max)somestuff) as 'somestuff' from tableB
I'd be wary of changing the UNION to UNION ALL since although, at present, the assumption is that there are no duplicates, I would assume this can't be guaranteed, since otherwise the query would have specified a UNION ALL in the first place!
Of couse, if this is an ad hoc query, rather than production code, than anything that works (and isn't ridiculously poor in performance) is acceptable! š
Derek
November 6, 2008 at 11:02 am
In MHO, making a change to the underlying table structure is NOT a workaround. (period!) Therefore, the only "workaround" solution is to change the select statement. š
Joe Burdette
hanesbrands.com
November 19, 2008 at 10:02 am
Even varchar() has limited size to 4000.
January 26, 2009 at 2:49 pm
J (11/6/2008)
Sorry - you were wrongNo. YOU ARE wrong.
It does not matter if there are duplicates or not, because the question specifically mentioned that there were no duplicates.
So "UNION ALL" is entirely satisfactory.
And modifying the structure of tables is hardly a "workaround". There are consequences to doing this.
Now, gimme my points! And double them for amends! Or else !
I'm a hundred percent in agreement with this reply. Plus the varchar(max) option doesn't exists in SQL 2000, which is where most SQL Server databases still are.
The answer is wrong, completely wrong!
Tom
Tom
January 26, 2009 at 3:06 pm
Tom.Thomson (1/26/2009)
J (11/6/2008)
Sorry - you were wrongNo. YOU ARE wrong.
It does not matter if there are duplicates or not, because the question specifically mentioned that there were no duplicates.
So "UNION ALL" is entirely satisfactory.
And modifying the structure of tables is hardly a "workaround". There are consequences to doing this.
Now, gimme my points! And double them for amends! Or else !
I'm a hundred percent in agreement with this reply. Plus the varchar(max) option doesn't exists in SQL 2000, which is where most SQL Server databases still are.
The answer is wrong, completely wrong!
Tom
Unfortunately, the question specifically stated SQL Server 2005, as shown in the following quote from the question:
You have a default SQL2005 Standard.installation with 2 tables:
So this comes down to reading the WHOLE question before answering.
January 26, 2009 at 3:10 pm
Joe Burdette (11/6/2008)
In MHO, making a change to the underlying table structure is NOT a workaround. (period!) Therefore, the only "workaround" solution is to change the select statement. š
No need to change the structure of the tables. I posted a workaround that would use a view over the tables. Derek Dongray also posted a solution whar you cast the text columns as varchar(max) in the select statements directly.
The best solution, however, would have been to build the tables in SQL Server 2005 using the varchar(max) to begin with.
June 9, 2009 at 4:18 am
I am not getting the second option to change UNION to UNION all
Deepak Kumar Sharma
January 6, 2010 at 6:26 am
Happy wif the question and the answer...
January 8, 2010 at 7:42 pm
Lynn Pettis (1/26/2009)
Tom.Thomson (1/26/2009)
J (11/6/2008)
Sorry - you were wrongNo. YOU ARE wrong.
It does not matter if there are duplicates or not, because the question specifically mentioned that there were no duplicates.
So "UNION ALL" is entirely satisfactory.
And modifying the structure of tables is hardly a "workaround". There are consequences to doing this.
Now, gimme my points! And double them for amends! Or else !
I'm a hundred percent in agreement with this reply. Plus the varchar(max) option doesn't exists in SQL 2000, which is where most SQL Server databases still are.
The answer is wrong, completely wrong!
Tom
Unfortunately, the question specifically stated SQL Server 2005, as shown in the following quote from the question:
You have a default SQL2005 Standard.installation with 2 tables:
So this comes down to reading the WHOLE question before answering.
Mea maxima culpa! I should read more carefully, my addition about sql 2000 was totally irrelevant.
BUT: union all is still entirely satisfactory, since there are known to be no duplicates (part of the probl;em, statement) - and union instead of union all will perform less well (since it has to do the unneeded check for duplicates). AND making modifications to table structure is NOT a good workaround, there are potentially many side effects. I'm not sure if it was you who originally made those comments or someone else, but that was what I was agreeing with.
Tom
Tom
Viewing 15 posts - 16 through 29 (of 29 total)
You must be logged in to reply to this topic. Login to reply