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

UNION error Expand / Collapse
Author
Message
Posted Thursday, November 6, 2008 9:10 AM
SSC-Addicted

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

Group: General Forum Members
Last Login: Yesterday @ 9:05 PM
Points: 441, Visits: 933
Now, this is a workaround I can live with. Good idea.

But I am still miffed at not having my points. (grin).
Post #598268
Posted Thursday, November 6, 2008 9:18 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, February 18, 2014 7:14 AM
Points: 1,344, Visits: 1,983
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
Post #598284
Posted Thursday, November 6, 2008 11:02 AM


SSC-Addicted

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

Group: General Forum Members
Last Login: 2 days ago @ 2:56 PM
Points: 437, Visits: 411
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. ;)


Regards,

Joe Burdette
hanesbrands.com
Post #598399
Posted Wednesday, November 19, 2008 10:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, January 26, 2009 6:13 PM
Points: 1, Visits: 6

Even varchar() has limited size to 4000.
Post #605263
Posted Monday, January 26, 2009 2:49 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 8:31 AM
Points: 8,707, Visits: 9,255
J (11/6/2008)
Sorry - you were wrong

No. 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
Post #643715
Posted Monday, January 26, 2009 3:06 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:06 PM
Points: 23,276, Visits: 31,996
Tom.Thomson (1/26/2009)
J (11/6/2008)
Sorry - you were wrong

No. 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.




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #643731
Posted Monday, January 26, 2009 3:10 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:06 PM
Points: 23,276, Visits: 31,996
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.




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #643738
Posted Tuesday, June 9, 2009 4:18 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Thursday, August 7, 2014 5:16 AM
Points: 693, Visits: 346
I am not getting the second option to change UNION to UNION all

Deepak Kumar Sharma
Post #731293
Posted Wednesday, January 6, 2010 6:26 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, November 5, 2013 6:08 AM
Points: 1,079, Visits: 591
Happy wif the question and the answer...

What you don't know won't hurt you but what you know will make you plan to know better
Post #842723
Posted Friday, January 8, 2010 7:42 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 8:31 AM
Points: 8,707, Visits: 9,255
Lynn Pettis (1/26/2009)
Tom.Thomson (1/26/2009)
J (11/6/2008)
Sorry - you were wrong

No. 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
Post #844795
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse