INSERT INTO

  • Is there a way to create a table based on the results of a query.

    I need some sort of version of

    (SELECT * from table_name) INSERT INTO test.dbo.employeebilling

    Thanks

    -WM

  • Look up the "SELECT INTO" statement in BOL.  Using SELECT INTO will create a table based on a select statement.  Here is an example:

    USE AdventureWorks;GOSELECT c.FirstName, c.LastName, e.Title, a.AddressLine1, a.City, sp.Name AS [State/Province], a.PostalCodeINTO dbo.EmployeeAddressesFROM Person.Contact AS cJOIN HumanResources.Employee AS e ON e.ContactID = c.ContactIDJOIN HumanResources.EmployeeAddress AS ea ON ea.EmployeeID = e.EmployeeIDJOIN Person.Address AS a on a.AddressID = ea.AddressIDJOIN Person.StateProvince as sp ON sp.StateProvinceID = a.StateProvinceID;GO

    Gregory A. Larsen, MVP

  • Thanks

    -WM

     

    Worked perfectly

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply