Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert custom values with 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

like image 577
coolstoner Avatar asked Sep 29 '16 09:09

coolstoner


1 Answers

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)
like image 72
juergen d Avatar answered Sep 20 '22 12:09

juergen d