blog post

INSERT INTO SELECT copies data from one table to another table.
INSERT INTO SELECT requires that data types in source and target tables match.

The SQL INSERT INTO SELECT syntax

The general syntax is:
INSERT INTO table-name (column-names)
SELECT column-names 
 FROM table-name
WHERE condition

SQL INSERT SELECT INTO

Problem: Copy all Canadian suppliers into the Customer table

INSERT INTO Customer (FirstName, LastName, City, Country, Phone)
SELECT LEFT(ContactName, CHARINDEX(' ',ContactName) - 1) AS FirstName, 
       SUBSTRING(ContactName, CHARINDEX(' ',ContactName) + 1, 100) AS LastName, 
       City, Country, Phone
  FROM Supplier
 WHERE Country = 'Canada'

LEFT, CHARINDEX, and SUBSTRING are built-in functions.

  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information