Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 22nd, 2004, 09:22 AM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default oledbcommand and sql query problem

first of all aorry for my bad english

i have a problem below:
 i was searching to change ibuyspy store of microsoft to use access db and not sqlserver

there is a function, This displays a list of other products
 also purchased with a specified product. In sql server there is a stored procedure:

CREATE Procedure CustomerAlsoBought
(
    @ProductID int
)
As

/* We want to take the top 5 products contained in
    the orders where someone has purchased the given Product */
SELECT TOP 5
    OrderDetails.ProductID,
    Products.ModelName,
    SUM(OrderDetails.Quantity) as TotalNum

FROM
    OrderDetails
  INNER JOIN Products ON OrderDetails.ProductID = Products.ProductID

WHERE OrderID IN
(
    /* This inner query should retrieve all orders that have contained the productID */
    SELECT DISTINCT OrderID
    FROM OrderDetails
    WHERE ProductID = @ProductID
)
AND OrderDetails.ProductID != @ProductID

GROUP BY OrderDetails.ProductID, Products.ModelName

ORDER BY TotalNum DESC


GO

this stored procedure is call as parameter in oledbcommand

now in access i have change it with sql query:

Dim myCommand As OleDbCommand = New OleDbCommand("SELECT TOP 5 OrderDetails.ProductID, Products.ModelName, SUM(OrderDetails.Quantity) " & _
             "FROM OrderDetails INNER JOIN Products ON OrderDetails.ProductID = Products.ProductID WHERE OrderID IN (SELECT DISTINCT OrderID FROM OrderDetails WHERE ProductID = ?) AND (OrderDetails.ProductID <> ?) " & _
                  "GROUP BY OrderDetails.ProductID, Products.ModelName ORDER BY SUM(OrderDetails.Quantity) DESC", myConnection)

but this query don't work.
Work only if where clause is:
WHERE OrderID IN (SELECT DISTINCT OrderID FROM OrderDetails WHERE ProductID = ?) (DISPLAY PRODUCT PURCHASED WITH PRODUCTID)
or:
WHERE (OrderDetails.ProductID <> ?) (cut productid as product PURCHASED WITH PRODUCTID)
not work with both clause

please,
i hope that anyone can help me, thanks in advance

 
Old July 22nd, 2004, 09:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

The First thing I noticed is a error in ur SP:
Code:
CREATE Procedure CustomerAlsoBought
<s>(
    @ProductID int
)</s>As

/* We want to take the top 5 products contained in
    the orders where someone has purchased the given Product */
SELECT  TOP 5 
    OrderDetails.ProductID,
    Products.ModelName,
    SUM(OrderDetails.Quantity) as TotalNum ...



Code:
CREATE Procedure CustomerAlsoBought
    @ProductID int
As

/* We want to take the top 5 products contained in
    the orders where someone has purchased the given Product */
SELECT  TOP 5 
    OrderDetails.ProductID,
    Products.ModelName,
    SUM(OrderDetails.Quantity) as TotalNum ...


Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query Problem mike.chary SQL Server 2005 1 September 26th, 2007 06:19 AM
SQL Query problem skarthikk SQL Server 2000 1 August 7th, 2006 02:20 AM
SQL Query problem caterpillar SQL Server 2000 2 August 2nd, 2006 07:59 PM
SQL query problem - Need Help Settt Biztalk 0 September 12th, 2005 09:32 AM
sql query problem Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 October 14th, 2004 07:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.