Greetings,
Here's any easy way to visualize the problem
(and solve it
.
This is being solved with the RAC utility for S2k.
No complex sql coding necessary.Just real simple
stuff
You can simply rank runs of DownCode.
create table #Nick([ID] int primary key,DownCode int)
go
insert #Nick values(1,109)
insert #Nick values(2,110)
insert #Nick values(3,109)
insert #Nick values(4,110)
insert #Nick values(5,110)
insert #Nick values(6,110)
insert #Nick values(7,109)
insert #Nick values(8,109)
insert #Nick values(9,110)
insert #Nick values(10,109)
insert #Nick values(11,109)
We create 2 ranks/counters.The DCrank counter increments
every time there is a new DownCode based on the
ordering of ID.If the next DownCode is the same
as the previous one the counter stays the same.
This counter thus identifies all the different runs
of DownCode.Within a run of DownCode another counter (DCnter)
ranks the values from 1 to N.
Exec Rac
@transform='_dummy_',
@rows='DownCode & [ID]',
@rowsort='[ID]', -- Sort DownCode by [ID] to keep
-- their sequence (sort order).
@pvtcol='Report Mode',
@from='#Nick',@grand_totals='n',@rowbreak='n',
-- Define runs of DownCode values based on ID sort order.
@rowindicators='DownCode{DCrank}',
-- Number from 1 to N the same value DownCodes in each run.
@rowcounters='DownCode{DCnter}',
@counterdatatype='int',
@defaultexceptions='dumy'
DownCode ID DCrank DCnter
-------- ---- ----------- -----------
109 1 1 1
110 2 2 1
109 3 3 1
110 4 4 1
110 5 4 2
110 6 4 3
109 7 5 1
109 8 5 2
110 9 6 1
109 10 7 1
109 11 7 2
Check out DCrank and DCnter.
I am trying to build a query that will select records
only if it is not equal to the previous record
This translates to picking the records where Dcnter=1.
(DCrank) is not necessary for the solution).
Here is the solution.
Exec Rac
@transform='_dummy_',
@rows='DownCode & [ID]',@rowsort='[ID]',
@pvtcol='Report Mode',
@from='#Nick',@grand_totals='n',@rowbreak='n',
@rowcounters='DownCode{DCnter}',
@counterdatatype='int',
@select='select [ID],DownCode
from rac
where DCnter=1
order by 1*DownCode,1*[ID]'
ID DownCode
---- --------
1 109
3 109
7 109
10 109
2 110
4 110
9 110
Maybe someone wants to translate this to Access code
.
For S2k check out RAC v2.2 and QALite @
www.rac4sql.net