Hi,
Does anyone know how i could add a incrementing field to a select statement.
at the moment i have the following:
SELECT X,Y,
(SELECT COUNT(*)
FROM dbo.tbldo e2
WHERE e2.doid <= dbo.tblDO.doID) AS rank
from dbo.tblDO INNER JOIN
dbo.tblMA_XY ON dbo.tblDO.doID = dbo.tblMA_XY.do ID INNER JOIN
dbo.tblMA_MA ON dbo.tblMA_XY.MA _MAIN_ID = dbo.tblMA_MA.MA _MAIN_ID
WHERE (dbo.tblMA_XY.p urchaseprice > 357000) and (dbo.tblMA_XY.p urchaseprice < 500000)
ORDER BY rank
the problem with this statement is that the rank is not sequential because the id i am using in my subquery is not sequential.
for example the results look like this:
X Y rank
-34.020559 18.348137 1
-34.041561 18.369392 1452
-34.035796 18.361704 2470
-34.036907 18.361067 2488
-34.041291 18.369034 2910
-34.040666 18.368614 2946
-34.040167 18.35322 3272
-34.036984 18.363736 4768
instead of:
X Y rank
-34.020559 18.348137 1
-34.041561 18.369392 2
-34.035796 18.361704 3
-34.036907 18.361067 4
-34.041291 18.369034 5
-34.040666 18.368614 6
-34.040167 18.35322 7
-34.036984 18.363736 8
Does anyone know how i could add a incrementing field to a select statement.
at the moment i have the following:
SELECT X,Y,
(SELECT COUNT(*)
FROM dbo.tbldo e2
WHERE e2.doid <= dbo.tblDO.doID) AS rank
from dbo.tblDO INNER JOIN
dbo.tblMA_XY ON dbo.tblDO.doID = dbo.tblMA_XY.do ID INNER JOIN
dbo.tblMA_MA ON dbo.tblMA_XY.MA _MAIN_ID = dbo.tblMA_MA.MA _MAIN_ID
WHERE (dbo.tblMA_XY.p urchaseprice > 357000) and (dbo.tblMA_XY.p urchaseprice < 500000)
ORDER BY rank
the problem with this statement is that the rank is not sequential because the id i am using in my subquery is not sequential.
for example the results look like this:
X Y rank
-34.020559 18.348137 1
-34.041561 18.369392 1452
-34.035796 18.361704 2470
-34.036907 18.361067 2488
-34.041291 18.369034 2910
-34.040666 18.368614 2946
-34.040167 18.35322 3272
-34.036984 18.363736 4768
instead of:
X Y rank
-34.020559 18.348137 1
-34.041561 18.369392 2
-34.035796 18.361704 3
-34.036907 18.361067 4
-34.041291 18.369034 5
-34.040666 18.368614 6
-34.040167 18.35322 7
-34.036984 18.363736 8
Comment