Sunday, 8 June 2014

Create New Table From SELECT SQL

The Reporter's Assistant
Photo Credits: images.businessweek.com
In Visual Foxpro 9.0, it's a norm to do a SELECT statement that writes all the queried records to a new table. This saves you time from making a new table along with all the fields within and fill it with records later from a SELECT query.

A simple SELECT statement like the example below creates a new table in VFP from a query:


SELECT field1, field2 FROM SomeTable Into Table NewTable

In MS SQL Server, the syntax is similar with changes so minor that they're almost alike except that the "Table" clause is dropped and the "into" is added before the "from" statement.

SELECT field1, field2 INTO SomeData.DBO.NewTable FROM SomeTable

Such command is useful in SQL Server if you want to make a temporary repository of your multiple queries for joining them into one final set of records which is better than having to sacrifice speed in favor of views.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...