> Thanks James,
>
> It works perfect. Is there a way you could breakdown the statement so I
> could understand it a little better?
>
> Beagle
I'll try.
tblRawData
RDID Raw_Data
1 @S1
2 A02F
3 A12F
4 A22F
5 @TPO
6 @TPC
SELECT Raw_Data, (SELECT Count(A.Raw_Data) FROM tblRawData AS A WHERE
A.RDID <= tblRawData.RDID AND Left([Raw_Data], 1) = "@") AS Tag FROM
tblRawData;
When the query is at tblRawData.RDID = 1 you get:
@S1, (SELECT Count(Raw_Data) FROM tblRawData WHERE RDID <= 1 AND
Left([Raw_Data], 1) = "@") AS Tag
= @S1, 1
When tblRawData.RDID = 2 you get:
A02F, (SELECT Count(Raw_Data) FROM tblRawData WHERE RDID <= 2 AND
Left([Raw_Data], 1) = "@") As Tag
= A02F, 1 + 0
The 0 is because the leftmost character of A02F is not '@'
When tblRawData.RDID = 3 you get:
A12F, (SELECT Count(Raw_Data) FROM tblRawData WHERE RDID <= 3 AND
Left([Raw_Data], 1) = "@") As Tag
= A12F, 1 + 0 + 0
When tblRawData.RDID = 4 you get:
A22F, (SELECT Count(Raw_Data) FROM tblRawData WHERE RDID <= 4 AND
Left([Raw_Data], 1) = "@") As Tag
= A22F, 1 + 0 + 0 + 0
When tblRawData.RDID = 5 you get:
@TPO, (SELECT Count(Raw_Data) FROM tblRawData WHERE RDID <= 5 AND
Left([Raw_Data], 1) = "@") As Tag
= @TPO, 1 + 0 + 0 + 0 + 1
When tblRawData.RDID = 6 you get:
@TPC, (SELECT Count(Raw_Data) FROM tblRawData WHERE RDID <= 6 AND
Left([Raw_Data], 1) = "@") As Tag
= @TPC, 1 + 0 + 0 + 0 + 1 + 1
Note: The query assumes that there are no records with Raw_Data = Null.
James A. Fortune
MPAPoster@FortuneJames.com
Beagle - 04 Oct 2007 01:51 GMT
Thanks James, Very Cool.... This will gove me someting to think about.
> > Thanks James,
> >
[quoted text clipped - 60 lines]
> James A. Fortune
> MPAPoster@FortuneJames.com
Beagle - 19 Oct 2007 13:52 GMT
James,
Having a problem appying the SQL statement.
The main datatable has 7,000 rows of data (not very much). When the SQL
statement is applied, the query will not finish running. If I reduce the
number of records to 58 from 7,000, then the query will finish running.
Any suggestions on how I could keep the 7,000+ rows of data and have the
query finish?
Thanks,
Beagle
> > Thanks James,
> >
[quoted text clipped - 60 lines]
> James A. Fortune
> MPAPoster@FortuneJames.com
James A. Fortune - 21 Oct 2007 06:04 GMT
> James,
>
[quoted text clipped - 10 lines]
>
> Beagle
Even 7,000 records should not cause the query to take over a couple of
minutes. Make sure RDID is the primary key and that Raw_Data is
indexed. If it's too slow after doing that, post back and I'll try
writing a VBA routine that makes a single pass through the data.
James A. Fortune
MPAPoster@FortuneJames.com