La sintaxis es:
- INSERT INTO table-name (column-names)
- SELECT column-names
- FROM table-name
- WHERE condition
SQL INSERT SELECT INTO
Problema: Copiar todos los Canadian suppliers en la tabla Customer
La sentencia sql:
- 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'
Resultado: