Some years later, this conversations is still usefull, thanks to both.
I have a similar problem and I'm trying to apply the same "trick"
using a sub-query.
But as soon as I introduce a WHERE clause in the sub-query Access
crashes... any hints?
My Table has 30.121 registers could it be too much for this type of
recursive sub-queries?
My query tries to give a serial number the changes of price in a
table of articles. This is in order to be able to filter later for
example the last 3 prices that a certain article has had and the
dates in which they were changed:
SELECT tblPriceHistory.Article, tblPriceHistory.Date,
tblPriceHistory.Price, (SELECT Count(*) FROM tblPriceHistory AS Temp
WHERE (Temp.Article=tblPriceHistory.Article) AND (Temp.Date <=
tblPriceHistory.Date)) AS ItemNo
FROM tblPriceHistory;
Thanks for any help,
JBB
I have a query that sorts infomation in a particular sequence. I
want to put an expression in the query that numbers the records
sequentially. Is there a simple expression I can enter to tell me
the row number as a field in the query?
On Thursday, June 21, 2007 11:47 PM Ken Snell \(MVP\) wrote:
You'll need a field to show the ranking. In order to give you an
example, post the SQL statement of the query that you're using now
and identify what the primary key field(s) are that are in the
query. --
Ken Snell
<MS ACCESS MVP>
news:
[email protected]...
On Friday, June 22, 2007 12:37 AM Neville wrote:
Hi Ken
Thanks for the response. The query is:
SELECT tblMeetingItem.MeetingItemNo, tblMeetingItem.MeetingNo,
tblMeetingItem.Description, tblMeetingItem.SeqNo,
tblMeetingItem.Time, tblMeetingItem.Responsible,
tblMeetingItem.Outcome, tblMeetingItem.Resolved FROM tblMeetingItem
ORDER BY tblMeetingItem.SeqNo;
The PK is MeetingItemNo but the items are in SeqNo order and I
wanted to number them in that order.
"Ken Snell (MVP)" wrote:
SELECT tblMeetingItem.MeetingItemNo, tblMeetingItem.MeetingNo,
tblMeetingItem.Description, tblMeetingItem.SeqNo,
tblMeetingItem.Time, tblMeetingItem.Responsible,
tblMeetingItem.Outcome, tblMeetingItem.Resolved, (SELECT
Count(T.SeqNo) FROM tblMeetingItem AS T
WHERE T.SeqNo <= tblMeetingItem.SeqNo
ORDER BY T.SeqNo) AS RecordNumber
FROM tblMeetingItem
ORDER BY tblMeetingItem.SeqNo;
--
Ken Snell
<MS ACCESS MVP>
news:
[email protected]...
On Friday, June 22, 2007 8:37 PM Neville wrote:
Thanks Ken but got an error. You tried to execute a query that
does not include the specified expression 'T.SeqNo' as part of
an aggregate function. I am getting a bit out of my depth here
(but learning fast). Can you make any suggestions?
Thanks
"Ken Snell (MVP)" wrote:
On Friday, June 22, 2007 10:28 PM John Spencer wrote:
Drop the order by in the sub-query. It is not needed AND it is
what is causing the error.
SELECT tblMeetingItem.MeetingItemNo, tblMeetingItem.MeetingNo,
tblMeetingItem.Description, tblMeetingItem.SeqNo,
tblMeetingItem.Time, tblMeetingItem.Responsible,
tblMeetingItem.Outcome, tblMeetingItem.Resolved,
(SELECT Count(T.SeqNo)
FROM tblMeetingItem AS T
WHERE T.SeqNo <= tblMeetingItem.SeqNo) AS RecordNumber
FROM tblMeetingItem
ORDER BY tblMeetingItem.SeqNo;
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
NevilleT wrote:
On Friday, June 22, 2007 10:54 PM Neville wrote:
No. That was not it. Deleted the Order By and got the same
error.
"John Spencer" wrote:
SELECT tblMeetingItem.MeetingItemNo, tblMeetingItem.MeetingNo,
tblMeetingItem.Description, tblMeetingItem.SeqNo,
tblMeetingItem.Time, tblMeetingItem.Responsible,
tblMeetingItem.Outcome, tblMeetingItem.Resolved, (SELECT
Count(*) FROM tblMeetingItem AS T
WHERE T.SeqNo <= tblMeetingItem.SeqNo
FROM tblMeetingItem
ORDER BY tblMeetingItem.SeqNo;
--
Ken Snell
<MS ACCESS MVP>
message
news:
[email protected]...
On Saturday, June 23, 2007 2:56 AM Neville wrote:
Well done Ken! There was a missing bracket but it worked.
I have had to add on a small section to make it work.
Basically each meeting has many items each with a sequence
number. Hence meeting one might have sequence 1, 2, 3, 4
and meeting two 1, 2, 4, 7. Screws up the sequence numbers
if I look at them all (If there are 2 sequence number 1's
the number from the query is 2 for both of the 1's. Had to
apply a where clause to only look at items relating to the
meeting displayed on the screen.
Just for the record, the final working SQL is
SELECT tblMeetingItem.MeetingItemNo,
tblMeetingItem.MeetingNo, tblMeetingItem.Description,
tblMeetingItem.SeqNo, tblMeetingItem.Time,
tblMeetingItem.Responsible, tblMeetingItem.Outcome,
tblMeetingItem.Resolved, (SELECT Count(*) FROM
tblMeetingItem AS T WHERE T.MeetingNo =
[Forms]![frmMeetings]![MeetingNo] AND T.SeqNo <=
tblMeetingItem.SeqNo) AS ItemNo
FROM tblMeetingItem
WHERE
(((tblMeetingItem.MeetingNo)=[Forms]![frmMeetings]![MeetingNo]))
ORDER BY tblMeetingItem.SeqNo;
Thanks again Ken for your valuable assistance.
"Ken Snell (MVP)" wrote:
On Saturday, June 23, 2007 12:24 PM Ken Snell \(MVP\) wrote:
Sorry about that -- it was pretty late last night when I
typed that.... < g
Glad it is working now.
Submitted via EggHeadCafe
New Features Of Microsoft Outlook 2010