SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 8th, 2004, 09:57 AM
Schadrach Schadrach is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 55 Schadrach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 17 m 53 sec
Reputation Power: 5
SQL query acting differently in Access and from ADO.

I've got a pain in the *** of a query. It looks up fields in other queries to get data. I'll layout all the queries referenced here.

BookedByOrderNo:
Code:
SELECT WorkOrderNo AS OrderNo, Sum(TotalCost) AS BookedCost
FROM WorkOrderLineItems
WHERE (ItemID Not In ('96ssssss','96SSSSSS','97mmmmmm','97MMMMMM','9606  0033','96049001','96060025','96049000')) And Deleted=False And Status<>'F'
GROUP BY WorkOrderNo;


FutureByOrderNo:
Code:
SELECT WorkOrderLineItems.WorkOrderNo AS OrderNo, Sum(WorkOrderLineItems.TotalCost) AS FutureCost
FROM WorkOrderLineItems
WHERE (((WorkOrderLineItems.ItemID) Not In ('96ssssss','96SSSSSS','97mmmmmm','97MMMMMM','9606  0033','96049001','96060025','96049000')) AND ((WorkOrderLineItems.Deleted)=False) AND ((WorkOrderLineItems.Status)='F'))
GROUP BY WorkOrderLineItems.WorkOrderNo;


LaborByOrderNo:
Code:
SELECT WorkOrderNo AS OrderNo, Sum(TotalCost) AS LaborCost
FROM WorkOrderLineItems
WHERE Deleted=False And ItemID In ('96060033','96049001','96060025','96049000')
GROUP BY WorkOrderNo;


ResaleByOrderNo:
Code:
SELECT WorkOrderLineItems.WorkOrderNo AS OrderNo, IIf(Sum(UnitResale)=0,Sum(WorkOrderLineItems.Total  Cost),Sum(WorkOrderLineItems.TotalResale)) AS SalesQuote
FROM WorkOrderLineItems
WHERE (((WorkOrderLineItems.Deleted)=False) AND ((WorkOrderLineItems.ItemID) Like '9?mmmmmm'))
GROUP BY WorkOrderLineItems.WorkOrderNo;


And here's the query that behaves differently if I view it from within Access vs using an ADO call, WORecap:
Code:
SELECT WorkOrders.OrderNo, IIf(IsNull([LaborCost]),0,[LaborCost]) AS LaborC, IIf(IsNull([BookedCost]),0,[BookedCost]) AS BookedC, IIf(IsNull([FutureCost]),0,[FutureCost]) AS FutureC, [BookedC]+[FutureC] AS MaterialCost, [LaborC]+[MaterialCost] AS TotalCost, ResaleByOrderNo.SalesQuote AS SalesQ, [SalesQ]-[TotalCost] AS Profit, WorkOrders.Active
FROM (((WorkOrders LEFT JOIN BookedByOrderNo ON WorkOrders.OrderNo = BookedByOrderNo.OrderNo) LEFT JOIN FutureByOrderNo ON WorkOrders.OrderNo = FutureByOrderNo.OrderNo) LEFT JOIN LaborByOrderNo ON WorkOrders.OrderNo = LaborByOrderNo.OrderNo) LEFT JOIN ResaleByOrderNo ON WorkOrders.OrderNo = ResaleByOrderNo.OrderNo
WHERE (((WorkOrders.Active)=True));


I was looking up WORecap from within an ASP.net page initially, and thought that it may have been an error in the page, but I just tried reading the query from another program, and it returned the same results. NULL for the SalesQ column.

Reply With Quote
  #2  
Old September 8th, 2004, 11:41 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
I would need to see data and your ADO Call Code, is it possible for you to post your Access DB with the form as well?

S-

Reply With Quote
  #3  
Old September 8th, 2004, 12:05 PM
Schadrach Schadrach is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 55 Schadrach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 17 m 53 sec
Reputation Power: 5
I can't post the DB itself, sorry, but here's the code I used to call it from the ASP.net page (OpenWORecapTable is a repeater):

Code:
<script runat="server">

    Sub Page_Load
         dim dbconn,sql,dbcomm,dbread
         dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/DB/Business.mdb"))
         dbconn.Open()

         SQL = "SELECT * FROM WORecap WHERE Active = TRUE"
         dbcomm = New OleDbCommand(SQL, dbconn)
         dbread = dbcomm.ExecuteReader()
         OpenWORecapTable.DataSource=dbread
         OpenWOrecapTable.DataBind()

         dbread.Close()
         dbConn.Close()
     End Sub

</script>


The data rows this produces are identical to the ones that Access gives me, except that SalesQ is NULL all the way down, and so is Profit, because it relies on the value of SalesQ for it's calculation.

Reply With Quote
  #4  
Old September 10th, 2004, 12:53 PM
Schadrach Schadrach is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 55 Schadrach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 17 m 53 sec
Reputation Power: 5
MWAHAHAHAHAHA! I've figured it out!

It's a wildcard thing. ASP uses _ and %, whereas Access uses ? and *. Since I'm calling the query from ASP, I have to use _ and %, even though the query is a stored query in Access.

If I switch from ?/* to _/%, then the query results are reversed -- that is, it nulls out the two columns in Access, but displays them correctly on the ASP page.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SQL query acting differently in Access and from ADO.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT