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

December 16th, 2003, 11:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

December 16th, 2003, 12:09 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

December 16th, 2003, 01:00 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: , , .
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Great, thanks Jeff - I took the option of changing the text Data Type
regards
Adam
|

June 26th, 2005, 04:15 PM
|
|
Registered User
|
|
Join Date: Jun 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, I had same problem. Using UNION ALL instead of UNION made the difference.
Have Fun
Rhys
|

July 14th, 2005, 05:16 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Me too. Thanks, Jeff
Giorgio
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |