MS Access alternative to SQL function ROW_NUMBER()

允我心安 提交于 2019-12-10 17:15:15

问题


I work with MS Access 07 and need a little help.

I have two tables TbProjectTeam and TbProjectList. I need to compare date of employee turn-out and date of project start. I used that SQL syntax:

SELECT [TbProjectTeam ].[Surname, name] 
FROM TbProjectTeam 
INNER JOIN TbProjectList
ON TbProjectTeam .[DateofTurnOut] <= TbProjectList.[DateOfStart] 
WHERE TbProjectList.[ID] = 1 
ORDER BY [Surname, name];

My aim is to replace 1 in TbSeznamUkolu.[ID] = 1 expression with something as ROW_NUMBER() OVER in SQL. MS Access doesn't support this function but unfortunately I need to know row index of all projects. I imagine that will be displayed matching employees for every row.

Can anyone help me please? Big thanks.


回答1:


MS Access has an AutoNumber data type that sets sequential numbers on records. Your data set would need to include an AutoNumber field to represent the ROW in T-SQL. Since the AutoNumber is numeric you could do > and < functions on it. The only problem with this is that the records will be numbered sequentially as they are added to the table. If you can control the sequence in which they are added then there is no problem, but if you were to add the AutoNumber field to an existing populated table, the sequence may not match your requirements.

I realise this question is a bit old but I hope this helps.




回答2:


DCOUNT function in spite of the efficiency issue provides a similar effect:

Just answered a similar answer here: How to show the record number in a MS Access report table?.



来源:https://stackoverflow.com/questions/18872305/ms-access-alternative-to-sql-function-row-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!