Get Value(s) from one table and Insert into column of another or same table

Solution

INSERT INTO destination_table (column names ) (select column names from the source_table );

e.g.

       INSERT INTO [dbo].[t_Menu]
            (Name,ParentId)VALUES
       ('CustomizedReports',(select id from t_Menu where Name='Reports'))
go

Explanation

Here I have inserted the value in the same table, you can write name of the other table in select statement if you want to get from other table. In the example, above ParentId is the ID of Reports and is being inserted into ParentId of Customized Reports

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started