using select (max(id)+1) in an insert is dangerous if there are multiple people updating the table at the same time. You have no guarantee that between the time you have selected max ID + 1 and the time the insert actually happens, a new record might have been inserted by someone else, meaning that when your insert statement finally hits, your max ID + 1 will not be … So I want to see the latest version and the value contained in [Data-a] for that record. SELECT [Doc No] ,max([Version No]) ,[Line No] ,[Data-a] ,[Data-b] FROM [table] GROUP BY [Doc No], [Line No], [Data-a], [Data-b] The problem obviously is ... if you notice in the first table the [Data-a] column has changing values (hence the need for version numbers. currently it is putting a new id_number in through getting the max, setting it as a variable (in CF) and adding 1, and THEN when the user submits the form it writes everything into the db. Il est par exemple possible de rechercher le produit le plus […] using select Max with insert – Learn more on the SQLServerCentral forums Firstly, it isn't thread safe, i.e. La fonction peut s’appliquée à des données numériques ou alphanumériques.
however... if while that user is entering the info onto the form, another user clicks 'Add New' they will get an identical id_number and all id_numbers have to be unique (and preferably incremental). I am trying to insert a new row and set the customer_id with max()+1. Dans le langage SQL, la fonction d’agrégation MAX() permet de retourner la valeur maximale d’une colonne dans un set d’enregistrement.