If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > SQL Join Error

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-10, 07:49
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
SQL Join Error

Hello All,

I am getting a bit stuck on the following sql string, I have an asp classic web page connected to an access 2007 database. I am trying to get the totals from a query called qrycondetailsextended totals, the fields I want from there are sumofextended price, perhaps sumofquantity too but most importantly for now is the sumofextended price field.

Here is my code:

strSQL = "SELECT tbl_ShipOrders.ship_order_id, tbl_ShipOrders.idate, tbl_ShipOrders.invamt, tbl_ShipOrders.receiver_id, tbl_ShipOrders.truck_id, " & _
"tbl_ShipOrders.ship_order_id, tbl_ShipOrders.sender_id, tbl_ShipOrders.provcred, tbl_shiporders.loaddate, " & _
"tbl_ShipOrders.loaddate, tbl_ShipOrders.Payment_id, tbl_truck_Details.truckid, qrycondetailsextendedtotals.sumofquantity" & _
"tbl_ShipOrders.del, tbl_ShipOrders.discountpr, Total.sumofquantity AS Total, Sender.company AS Sender_name, Sender.Tel_1 AS Sender_Tel, Sender.Tel_2 AS Sender_Tel2," & _
"Receiver.company AS Receiver_name, Receiver.Tel_1 AS Receiver_Tel, Receiver.Tel_2 AS Receiver_Tel2, Truck.Truck_Registration AS TruckReg " & _
"FROM (tbl_ShipOrders INNER JOIN tbl_Customers AS Sender " & _
"ON tbl_ShipOrders.Sender_ID = Sender.custid) " & _
"INNER JOIN tbl_Customers AS Receiver " & _
"ON tbl_ShipOrders.Receiver_ID = Receiver.custid " & _
"(tbl_shipOrders INNER JOIN qrycondetailsextendedtotals AS Total) " & _
"ON tbl_shipOrders.ship_order_ID = Total.ship_ID " & _
"WHERE tbl_ShipOrders.Loaddate Is Not Null " & _
"AND tbl_ShipOrders.Del=0 " & _
"AND tbl_ShipOrders.Payment_ID=4 " & _
"AND tbl_ShipOrders.Branch_ID = " & Branchid


I get this error:

"Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'tbl_ShipOrders.Receiver_ID = Receiver.custid tbl_shipOrders INNER JOIN qrycondetailsextendedtotals AS Total ON tbl_shipOrders.ship_order_ID = Total.ship_I'."

Using just:

strSQL = "SELECT tbl_ShipOrders.idate, tbl_ShipOrders.invamt, tbl_ShipOrders.receiver_id, tbl_ShipOrders.truck_id, " & _
"tbl_ShipOrders.ship_order_id, tbl_ShipOrders.sender_id, tbl_ShipOrders.provcred, tbl_shiporders.loaddate, " & _
"tbl_ShipOrders.loaddate, tbl_ShipOrders.Payment_id, " & _
"tbl_ShipOrders.del, tbl_ShipOrders.discountpr, Sender.company AS Sender_name, Sender.Tel_1 AS Sender_Tel, Sender.Tel_2 AS Sender_Tel2," & _
"Receiver.company AS Receiver_name, Receiver.Tel_1 AS Receiver_Tel, Receiver.Tel_2 AS Receiver_Tel2 " & _
"FROM (tbl_ShipOrders INNER JOIN tbl_Customers AS Sender " & _
"ON tbl_ShipOrders.Sender_ID = Sender.custid) " & _
"INNER JOIN tbl_Customers AS Receiver " & _
"ON tbl_ShipOrders.Receiver_ID = Receiver.custid " & _
"WHERE tbl_ShipOrders.Loaddate Is Not Null " & _
"AND tbl_ShipOrders.Del=0 " & _
"AND tbl_ShipOrders.Payment_ID=4 " & _
"AND tbl_ShipOrders.Branch_ID = " & Branchid


no problems, pulls the details out nicely, the problem is trying to create a further join from the qrycondetailsextendedtotals.

Any and all help will be fully appreciated

Thanks in Advance

Regards

Ben
Reply With Quote
  #2 (permalink)  
Old 02-21-10, 08:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
Code:
SELECT ...
  FROM ((
       tbl_ShipOrders 
INNER 
  JOIN tbl_Customers AS Sender 
    ON Sender.custid = tbl_ShipOrders.Sender_ID 
       ) 
INNER 
  JOIN tbl_Customers AS Receiver 
    ON Receiver.custid = tbl_ShipOrders.Receiver_ID
       )
INNER
  JOIN qrycondetailsextendedtotals AS Total
    ON Total.ship_ID = tbl_shipOrders.ship_order_ID
 WHERE ...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-21-10, 09:08
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
deleted deleted deleted deleted deleted deleted deleted deleted deleted deleted

Last edited by ben2203; 02-21-10 at 09:20. Reason: deleted
Reply With Quote
  #4 (permalink)  
Old 02-21-10, 09:19
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
Actually, I got this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Undefined function 'Nz' in expression.

/delivery.asp, line 91

with this code

strSQL = "SELECT tbl_ShipOrders.idate, tbl_ShipOrders.invamt, tbl_ShipOrders.receiver_id, tbl_ShipOrders.truck_id, " & _
"tbl_ShipOrders.ship_order_id, tbl_ShipOrders.sender_id, tbl_ShipOrders.provcred, tbl_shiporders.loaddate, " & _
"tbl_ShipOrders.loaddate, tbl_ShipOrders.Payment_id, Total.sumofquantity AS Total, qrycondetailsextendedtotals.sumofquantity, " & _
"tbl_ShipOrders.del, tbl_ShipOrders.discountpr, Sender.company AS Sender_name, Sender.Tel_1 AS Sender_Tel, Sender.Tel_2 AS Sender_Tel2," & _
"Receiver.company AS Receiver_name, Receiver.Tel_1 AS Receiver_Tel, Receiver.Tel_2 AS Receiver_Tel2 " & _
"FROM ((tbl_ShipOrders " & _
"INNER JOIN tbl_Customers AS Sender " & _
"ON Sender.custid = tbl_ShipOrders.Sender_ID) " & _
"INNER JOIN tbl_Customers AS Receiver " & _
"ON Receiver.custid = tbl_ShipOrders.Receiver_ID) " & _
"INNER JOIN qrycondetailsextendedtotals AS Total " & _
"ON Total.ship_ID = tbl_shipOrders.ship_order_ID " & _
"WHERE tbl_ShipOrders.Loaddate Is Not Null " & _
"AND tbl_ShipOrders.Del=0 " & _
"AND tbl_ShipOrders.Payment_ID=4 " & _
"AND tbl_ShipOrders.Branch_ID = " & Branchid
Reply With Quote
  #5 (permalink)  
Old 02-21-10, 09:43
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
Sorry, I had previously put in a syntax error, I meant to say thanks very much for your reply and I got this error, I researched it and it seems to be asp classic and access related, I tried using IFNULL in front of the query values but got nowhere, any ideas??
Reply With Quote
  #6 (permalink)  
Old 02-21-10, 09:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
the problem may lie in qrycondetailsextendedtotals

which of course i can't see
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 02-21-10, 10:26
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
I researched it and says something to do with null values

Qrycondetailsextendedtotals is a query based on another query called qrycondetailsextended, here is the sql:

SELECT QryConDetailsExtended.Ship_ID AS Ship_ID, Sum(QryConDetailsExtended.[Extended Price]) AS [SumOfExtended Price], Sum(QryConDetailsExtended.Quantity) AS SumOfQuantity, Sum(QryConDetailsExtended.Discount) AS SumOfDiscount
FROM QryConDetailsExtended
GROUP BY QryConDetailsExtended.Ship_ID;


the qrycondetailsextended sql is:

SELECT tbl_consignment_details.*, CCur(Nz([Quantity],0)*Nz([Shipment_price],0)-Nz([Discount],0)) AS [Extended Price], tbl_Products.Shipping_Price
FROM tbl_Products INNER JOIN tbl_consignment_details ON tbl_Products.ProductID = tbl_consignment_details.Product_ID;

All based on the northwind sample dbase
Reply With Quote
  #8 (permalink)  
Old 02-21-10, 10:30
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
About your book, the pdf version is as complete as the book version, right? probably a silly question but thought I'd clarify it, I am thinking of purchasing it as a reference aid, it would be nice to have the book but I've just purchased a tablet pc so I might start using that put lots of ebooks in there since I am on the road a lot.

You certainly taught me a great deal in a very short amount of time so I think it would be a great investment

Last edited by ben2203; 02-21-10 at 10:36.
Reply With Quote
  #9 (permalink)  
Old 02-21-10, 12:12
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
Got it, thank you so much for your help, please let me know about this book as I am really eager to start reading it!!!

You are a star!!!!
Reply With Quote
  #10 (permalink)  
Old 02-21-10, 18:11
SimonMT SimonMT is offline
Registered User
 
Join Date: Sep 2006
Posts: 265
Here's a tip.

Don't worry about how the Sql statement looks, one single string will do. What I do is put the Query into Access first and all the ASP is reads the query and applies the WHERE part of the SQL statement.

Doing this way you can get the SQL statement working in Access and later back it into Access if it ever goes wrong.

I used to do it your way but now that I using ASP.Net, the SQL statement is one continuous statement. Now its a doddle to test the SQL statement.

Simon
Reply With Quote
  #11 (permalink)  
Old 02-21-10, 18:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
Quote:
Originally Posted by ben2203 View Post
About your book, the pdf version is as complete as the book version, right?
yes it is, you get everything except the paper
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 02-22-10, 09:52
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
Quote:
Originally Posted by SimonMT View Post
Here's a tip.

Don't worry about how the Sql statement looks, one single string will do. What I do is put the Query into Access first and all the ASP is reads the query and applies the WHERE part of the SQL statement.

Doing this way you can get the SQL statement working in Access and later back it into Access if it ever goes wrong.

I used to do it your way but now that I using ASP.Net, the SQL statement is one continuous statement. Now its a doddle to test the SQL statement.

Simon
I like to see it, I am not new to SQL but I am by far an expert and often make a whole heap of mistakes, I guess I'll migrate to .net too since classic is ageing, thanks for the tip, eventually I'll get it and use the single string format.
Reply With Quote
  #13 (permalink)  
Old 02-22-10, 09:56
ben2203 ben2203 is offline
Registered User
 
Join Date: Feb 2010
Posts: 21
Quote:
Originally Posted by r937 View Post
yes it is, you get everything except the paper
figured it was but thought i'd check, kind of like the kindle that amazon have brought out, pretty cool stuff. Thanks again
Reply With Quote
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On