我想在执行:view
子句
INSERT INTO ...SELECT FROM ... WHERE
我想使用自定义值
插入INSERT INTO RoleMappingEmployee_Delete_History (
RoleMappingEmployeeKey,
SrKey,
RoleKey,
SubmittedDate,
SubmittedBy,
IsActive,
DeletedBy,
DeletedDateTime)
SELECT
RoleMappingEmployeeKey,
SrKey,
RoleKey,
SubmittedDate,
SubmittedBy,
IsActive,
DeletedBy,
DeletedDateTime
FROM
RoleMappingEmployee
WHERE
RoleMappingEmployeeKey IN (25902,38188,25887)
的值
答案 0 :(得分:4)
INSERT INTO RoleMappingEmployee_Delete_History (
RoleMappingEmployeeKey,
SrKey,
RoleKey,
SubmittedDate,
SubmittedBy,
IsActive,
DeletedBy,
DeletedDateTime)
SELECT
RoleMappingEmployeeKey,
SrKey,
RoleKey,
SubmittedDate,
SubmittedBy,
IsActive,
'peter',
getdate()
FROM
RoleMappingEmployee
WHERE
RoleMappingEmployeeKey IN (25902,38188,25887)
答案 1 :(得分:0)
您还可以使用ORIGINAL_LOGIN函数设置DeletedBy,它将返回执行操作的用户名,并帮助避免每次为此设置值或参数。类似地,您可以使用CURRENT_TIMESTAMP在DeletedDateTime中使用alternative,如下所示:
INSERT INTO RoleMappingEmployee_Delete_History (
RoleMappingEmployeeKey,
SrKey,
RoleKey,
SubmittedDate,
SubmittedBy,
IsActive,
DeletedBy,
DeletedDateTime)
SELECT
RoleMappingEmployeeKey,
SrKey,
RoleKey,
SubmittedDate,
SubmittedBy,
IsActive,
ORIGINAL_LOGIN(),
CURRENT_TIMESTAMP
FROM
RoleMappingEmployee
WHERE RoleMappingEmployeeKey IN (25902,38188,25887)