Chapter 4 QUERYING AND MODIFYING DATA 233 and,
Sunday, May 31st, 2009Chapter 4 QUERYING AND MODIFYING DATA 233 and, of course, allow for an employee discount (not implemented in the Northwind example). The query to perform this operation might look similar to the following: INSERT INTO Northwind.dbo.Customers SELECT EmployeeID, Northwind , FirstName + + LastName, Employee , Address, City, Region, PostalCode, Country, HomePhone, NULL FROM Northwind.dbo.Employees The SELECT list of the subquery must match the column list of the INSERT statement. If no column list is specified, the SELECT list must match the columns in the table or view being inserted into, as in the example. Note that NULL has been provided for a fax number at the end of the column list, because none is included in the employees table. The INSERT SELECT statement can be used to insert data from any viable source. This includes SQL Server tables, views, and sources outside SQL Server. Values can be inserted from any number of sources using a variety of options available to an INSERT operation. As you will see next, this is a very flexible operation and virtually any data source can be used. INSERT EXECUTE An EXECUTE statement that returns data with SELECT or READTEXT statements can be used to return the insert values to an INSERT operation. Each resultset must be compatible with the columns in the table or in the column list being used by the INSERT. In this manner a stored procedure can be executed and the data returned as input to a table. If an operation returns data with the READTEXT statement, each individual READTEXT statement can return a maximum of 1MB. The execute operation can also be used with extended procedures (not available in previous versions of SQL Server). Using an operation in this manner enables complex logic to be saved into a stored procedure, and the resulting output can be used for the insertion. For example, imagine you want to get a listing of top salespeople to establish year-end bonuses. You would like to place these records into a separate table. This operation would require four tables be queried on each of three servers and calculations be performed to determine each salesperson s ranking. If you create a procedure called pick_top_sales, the results of this procedure could be used to form the data for your table. The query would look similar to the following: INSERT Top_Sales EXECUTE pick_top_sales
If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.