Though this is an old question, this has worked for me, but I've never tested its efficiency...
SELECT
(SELECT COUNT(t1.SourceID)
FROM [SourceTable] t1
WHERE t1.SourceID<t2.SourceID) AS RowID,
t2.field2,
t2.field3,
t2.field4,
t2.field5
FROM
SourceTable AS t2
ORDER BY
t2.SourceID;
Some advantages of this method:
RowID
is calculated on its actual value and those that are less than it.Number
, String
or Date
).Final Thoughts
Though this will work with practically any data type, I must emphasise that, for some, it may create other problems. For instance, with strings, consider:
ID Description ROWID
aaa Aardvark 1
bbb Bear 2
ccc Canary 3
If I were to insert: bba Boar
, then the Canary
RowID
will change...
ID Description ROWID
aaa Aardvark 1
bbb Bear 2
bba Boar 3
ccc Canary 4