Greetings,
Hmm I wasn't sure if to post this here or the SQL server programming board, here goes:-
Using a sqlcommand is it possible to use subqueries in an INSERT statement?
I attempted the following (and numerous variations playing around with syntax):-
The scenario is the userID is hidden from the user and does not appear on the form, I want to find the last value (MAX) userId (integer) and increment by 1.
Errorcode 1046 suggests It can't be done with a subquery but was wondering if it can be done but was going the wrong way about it.
Any advice or tips would be appreciated.
Thanks
Rob
Hmm I wasn't sure if to post this here or the SQL server programming board, here goes:-
Using a sqlcommand is it possible to use subqueries in an INSERT statement?
I attempted the following (and numerous variations playing around with syntax):-
Code:
Using insertuser As New SqlCommand("INSERT INTO Users (UserID, Name, Password, Phone) " _
+ "VALUES((Select MAX(UserId)+1 as UserId FROM Users), @name, @password, @phone)", conn)
Errors with 1046: Subqueries are not allowed in this contect. Only scalar expressions are allowed.
The scenario is the userID is hidden from the user and does not appear on the form, I want to find the last value (MAX) userId (integer) and increment by 1.
Errorcode 1046 suggests It can't be done with a subquery but was wondering if it can be done but was going the wrong way about it.
Any advice or tips would be appreciated.
Thanks
Rob