Copying Data Between/Within Tables in Sql

Simple method of copying data between tables or within the same table in SQL.

The following can be used to copy data within its own table, altering fields as required:

INSERT INTO Table1
(

[Some_Id],
,[Position]
,[Name]
,[Description]
,[LastAction]

)

SELECT

954 as Some_Id,
,[Position]
,[Name]
,[Description]
,[LastAction]
FROM Table1 where Some_Id = 52

The following can be used to copy data from a different table:

INSERT INTO Table1
(

[Some_Id],
,[Position]
,[Name]
,[Description]
,[LastAction]

)

SELECT

43 as Some_Id,
,[Position]
,[Name_First] + ‘ ‘ + [Name_Last]
,[Job_Title]
,NOW()
FROM tblStaff where Job_TitleĀ  like ‘%developer%’

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>