INSERT INTO t_MT_User (ID, Badge, Name, Scope, comp_code, dept_code, [status])
VALUES ((SELECT MAX(ID) + 1 FROM t_MT_User), @userBadgeNumber, @userName, @userScope, @companyCode, @departmentCode, 1)
This query throws the following error:
Subqueries are not allowed in this context. Only scalar expressions are allowed.
If I change VALUES
to SELECT
, I get another error instead:
INSERT INTO t_MT_User (ID, Badge, Name, Scope, comp_code, dept_code, [status])
SELECT
((SELECT MAX(ID) + 1 FROM t_MT_User),
@userBadgeNumber, @userName, @userScope, @companyCode,
@departmentCode, 1)
Incorrect syntax near ','.
How do I achieve (SELECT MAX(ID) + 1 FROM t_MT_User)
in this context?