iPhone App Con Sept 27 -- www.iphonedevcon.com
Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 16th, 2003, 11:38 AM
Friend of Wrox
Points: 1,272, Level: 14
Points: 1,272, Level: 14 Points: 1,272, Level: 14 Points: 1,272, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default SQL QA Analyzer error

Hi there

I'm getting an error in my sql statement and am not sure why. I'm trying to append to select statements and output the result as one.

Here's the statement:

SELECT sp.ProductID, sp.SubCatID, sp.ProductCode, sp.ProductName, sp.ProductShort,
sp.ProductLong, sp.Price, b.Quantity FROM SpecialProducts sp, Basket b, Products p
WHERE sp.ProductID = p.ProductID AND b.CustomerID = '3' UNION SELECT
p.ProductID, p.CategoryID, p.SubCategoryID, p.ProductCode, p.ProductShort,
p.ProductLong, p.Price, b.Quantity FROM Products p, basket b
WHERE p.ProductID = b.ProductID AND b.CustomerID = '3'

and I get this error:

The text, ntext, or image data type cannot be selected as DISTINCT.

Any help greatly appreciated.

Many thanks

Adam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old December 16th, 2003, 12:09 PM
Friend of Wrox
Points: 2,591, Level: 21
Points: 2,591, Level: 21 Points: 2,591, Level: 21 Points: 2,591, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm surmising that one (or more) of the columns in your query is defined as a text (ntext) type.

The UNION operator by default eliminates duplicate rows from the resultset.  The duplicate eliminating operation is similar to a SELECT DISTINCT.  You can't use SELECT DISTINCT on a column that is text type.

Try UNION ALL which will not remove duplicates, or remove the text column(s).

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old December 16th, 2003, 01:00 PM
Friend of Wrox
Points: 1,272, Level: 14
Points: 1,272, Level: 14 Points: 1,272, Level: 14 Points: 1,272, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

Great, thanks Jeff - I took the option of changing the text Data Type

regards

Adam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old June 26th, 2005, 04:15 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I had same problem. Using UNION ALL instead of UNION made the difference.


Have Fun
Rhys


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old July 14th, 2005, 05:16 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Me too. Thanks, Jeff

Giorgio

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO.Net slower than SQL Server Query Analyzer s5g5r ADO.NET 1 January 26th, 2005 08:49 PM
SQL Query Analyzer bmains SQL Server 2000 3 June 23rd, 2004 05:58 PM
SQL Query Analyzer Save As ioates SQL Server 2000 1 May 18th, 2004 08:01 AM
xml result set truncated in sql query analyzer xologist SQL Server 2000 2 March 22nd, 2004 04:23 PM
Debugging in SQL 2000 QA chrislepingwell SQL Server 2000 3 June 25th, 2003 12:09 PM



All times are GMT -4. The time now is 03:21 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc