MAX () function with INSERT INTO?
-
hi I have following problem. i'd like to use the MAX() function to get the highest ID from a table. i've used is lik this:
INSERT INTO Table (ID, Employee, Project, Date, ...) VALUES (MAX(ID) + 1,@Employee,@Project,@Date, ...)
but this is not working. i've searched a bit in the internet that it's not possible to put functions into VALUES. so i'd like to know another way to solve this problem. thanks in advance greetz pdluke PS: sorry for my bad english -
hi I have following problem. i'd like to use the MAX() function to get the highest ID from a table. i've used is lik this:
INSERT INTO Table (ID, Employee, Project, Date, ...) VALUES (MAX(ID) + 1,@Employee,@Project,@Date, ...)
but this is not working. i've searched a bit in the internet that it's not possible to put functions into VALUES. so i'd like to know another way to solve this problem. thanks in advance greetz pdluke PS: sorry for my bad englishYou could either make the id an identity column, or you can get the value using a sub select:
insert into A
(id, ....)
values
((SELECT MAX(ID) FROM A), ...) -
You could either make the id an identity column, or you can get the value using a sub select:
insert into A
(id, ....)
values
((SELECT MAX(ID) FROM A), ...)yes an sub select is one possibility, but I'm using MSSQL and an sub select is not supported like in MySQL.
-
hi I have following problem. i'd like to use the MAX() function to get the highest ID from a table. i've used is lik this:
INSERT INTO Table (ID, Employee, Project, Date, ...) VALUES (MAX(ID) + 1,@Employee,@Project,@Date, ...)
but this is not working. i've searched a bit in the internet that it's not possible to put functions into VALUES. so i'd like to know another way to solve this problem. thanks in advance greetz pdluke PS: sorry for my bad english -
Why don't you make the ID a primary key and set its Identity to true, then it will auto increment by 1.
the problem is that I'm using this database via a WCF-Service. so multiuser accessibility is the main problem. If 2 users are saving their date at the same, who would this be solved with assigning the IDs? so I've tryed this with MAX(). I really don't know how it would act with the IDs. I would be grateful if someone could tell me if this could work like you say. greetz pdluke
-
the problem is that I'm using this database via a WCF-Service. so multiuser accessibility is the main problem. If 2 users are saving their date at the same, who would this be solved with assigning the IDs? so I've tryed this with MAX(). I really don't know how it would act with the IDs. I would be grateful if someone could tell me if this could work like you say. greetz pdluke
-
hi I have following problem. i'd like to use the MAX() function to get the highest ID from a table. i've used is lik this:
INSERT INTO Table (ID, Employee, Project, Date, ...) VALUES (MAX(ID) + 1,@Employee,@Project,@Date, ...)
but this is not working. i've searched a bit in the internet that it's not possible to put functions into VALUES. so i'd like to know another way to solve this problem. thanks in advance greetz pdluke PS: sorry for my bad english