coolstoner coolstoner - 2 months ago 13
SQL Question

How to insert custom values when doing INSERT INTO ... SELECT FROM

i would like to insert custom values along with table columns when i perform

INSERT INTO ...SELECT FROM ... WHERE
clause

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)


i would like to insert values for
DeletedBy,DeletedDateTime
with custom values

Answer
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)
Comments