23 Kasım 2008 Pazar

INSERT INTO SELECT

Ref: http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/

USE AdventureWorks
GO
    
----Create TestTable
CREATE TABLE TestTable (FirstName VARCHAR(100), LastName VARCHAR(100))
    
----INSERT INTO TestTable using SELECT
INSERT INTO TestTable (FirstNameLastName)
    
SELECT FirstNameLastName
    
FROM Person.Contact
    
WHERE EmailPromotion 2
    
----Verify that Data in TestTable
SELECT FirstNameLastName
    
FROM TestTable
    
----Clean Up Database
DROP TABLE TestTable
GO

Hiç yorum yok: