Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 May 11th, 2004, 11:35 AM
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help converting MySQL SELECT to JET-SQL

I have the following table:

Name Date value
test1 10/10/04 4
test2 10/10/04 2
test3 10/10/04 1
test4 10/10/04 3
test5 10/10/04 2
test6 10/10/04 1

I want to made a SELECT to return the following table

Name Date value
test1 10/10/04 4
test2 10/10/04 6
test3 10/10/04 7
test4 10/10/04 10
test5 10/10/04 12
test6 10/10/04 13

The MySQL syntax of the SELECT is:
SELECT name,data,@aux:=value+@aux

How can I do it in JET-SQL?


 
Old May 11th, 2004, 10:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
SELECT * FROM YourTable ORDER BY [Value]
I am a loud man with a very large hat. This means I am in charge
 
Old May 17th, 2004, 03:18 PM
Authorized User
 
Join Date: May 2004
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Steven, I think Alexendre is looking for a running total, not a sort by value. I suspect that this can only be done in a report and using a control with RunningSum function.

The numbers in his second display, third column are not values in ascending order, they are a running total caluclation of the values in his first example of the table contents. The second display is his query results of the table.

Using an alias in the query, like: Total:Value+Total ends up with an error because of a circular reference.
 
Old May 17th, 2004, 05:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah - right you are Bob.
Although, I guess you could also write a whole heap of queries and UNION them, but I agree, a running sum would be better

I am a loud man with a very large hat. This means I am in charge
 
Old May 18th, 2004, 11:05 AM
Authorized User
 
Join Date: Mar 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Rood67
Default

Download the qrysmp00 file from Micro$oft at this link. It has an example of how to do a running sum in one query.

http://support.microsoft.com/default...b;EN-US;207626


Hope this helps.

Rood67
Scott H.
 
Old May 19th, 2004, 01:37 AM
Authorized User
 
Join Date: May 2004
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reference to the sample, but I have had no luck working with it. Here are my observations. Note, I removed formatting from my tests.
==========================
This is from the sample referenced above:
SELECT Orders.EmployeeID AS EmpAlias, Sum(Orders.Freight) AS SumOfFreight, Format(DSum("Freight","Orders","[EmployeeID]<=" & [EmpAlias] & ""),"$0,000.00") AS RunTot
FROM Orders
GROUP BY Orders.EmployeeID;
=====================================

This is my test. It gives "#Error" in RunningTotal column:

SELECT tblTemp.Name, Sum(tblTemp.Value) AS SumOfValue, DSum("Value","tblTemp","[Name]<=" & [Name] & "") AS RunningTotal
FROM tblTemp
GROUP BY tblTemp.Name;
===================================

A second test gives Overall Total, but not running total. Overall total is same value on each line.

SELECT tblTemp.Name, Sum(tblTemp.Value) AS SumOfValue, DSum("Value","tblTemp",Name<=Name) AS RunningTotal
FROM tblTemp
GROUP BY tblTemp.Name;
 
Old May 19th, 2004, 06:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Looks like you're missing a set of single quotes
try this:
Code:
SELECT tblTemp.Name, Sum(tblTemp.Value) AS SumOfValue, 
DSum("Value","tblTemp","[Name]<='" & [Name] & "'") AS RunningTotal
FROM tblTemp
GROUP BY tblTemp.Name;
I am a loud man with a very large hat. This means I am in charge
 
Old May 19th, 2004, 06:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's assuming that tblTemp.Name is a text field of course

I am a loud man with a very large hat. This means I am in charge
 
Old May 19th, 2004, 08:16 PM
Authorized User
 
Join Date: May 2004
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good catch Steven......now it will only take me a year to break down and understand those additional quote marks. Why are they needed here?

They definitely are not in the sample code that was provided by Microsoft, regerenced by Rood67. And that code works for me. Is there some type of patch/change between versions that may have caused the need for additional quotes? I was doing test with Access 2000, and the samples are titled Access 2000 queries.
 
Old May 19th, 2004, 08:21 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Looks like you're referring to a value, not a column.

HTH,

Snib

<><





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting my sql select to use LEFT JOINs elfranko PHP Databases 0 December 1st, 2005 07:01 AM
Converting to MYSQL from sql server 2000 olambe BOOK: ASP.NET Website Programming Problem-Design-Solution 5 March 22nd, 2005 10:59 AM
Converting a Jet query to SQL that uses a function Mitch SQL Server 2000 5 February 28th, 2005 12:33 PM
Converting mysql arrays to strings robertjshillito Beginning PHP 3 February 25th, 2005 04:11 PM
converting MySQL tables to SQL Server using PHP vishal148 Access 2 July 3rd, 2004 10:48 AM





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