我正在尝试执行此SQL查询:
INSERT INTO ItemAssignments(EmployeeId, ItemId, ModifiedOn)
(SELECT Id FROM Employees WHERE Acronym ='ardsd',2,'2019-07-10 09:03:55.830'),
(SELECT Id FROM Employees WHERE Acronym ='bsadf',2,'2019-07-10 09:03:55.830'),
(SELECT Id FROM Employees WHERE Acronym ='casde',3,'2019-07-10 09:03:55.830'),
(SELECT Id FROM Employees WHERE Acronym ='dasas',3,'2019-07-10 09:03:55.830');
SELECT
表达式和下一个参数之间的错误。
我试图将SELECT放在方括号中-但这无济于事。
请告诉我在这种情况下我该怎么办?
答案 0 :(得分:2)
使用一个带有UNION的SELECT作为源:
INSERT INTO ItemAssignments(EmployeeId,ItemId,ModifiedOn)
SELECT id, 2, '2019-07-10 09:03:55.830'
FROM Employees
WHERE Acronym in ('ardsd', 'bsadf')
UNION ALL
SELECT id, 3, '2019-07-10 09:03:55.830'
FROM Employees
WHERE Acronym in ('casde', 'dasas');
答案 1 :(得分:1)
您似乎想要这样的逻辑:
INSERT INTO ItemAssignments(EmployeeId, ItemId, ModifiedOn)
SELECT Id,
(CASE WHEN Acronym in ('ardsd', 'bsadf') THEN 2
ELSE 3
END),
'2019-07-10 09:03:55.830'
FROM Employees
WHERE Acronym in ('ardsd', 'bsadf', 'casde', 'dasas')