SQL Server中Insert与Select的组合使用

王朝mssql·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

SQL Server中有示例数据库Northwind。新建表Sales用于存储销售信息,字段为EmployeeID,ProductID,SupplierID,CustomerID,OrderDate,UnitPrice,Total,Quantity,Discount。

下面的语句从Orders,Order Details, Employees,Products, Suppliers, Customers表选择相应的

数据插入Sales表:

insert into Sales(EmployeeID,ProductID,SupplierID,CustomerID,

OrderDate,UnitPrice,Total,Quantity,Discount)

select e.EmployeeID, p.ProductID, s.SupplierID,

c.CustomerID, o.OrderDate, od.UnitPrice,

od.Quantity*od.UnitPrice*(1.0-od.Discount)Total,

Od.Quantity, od.Discount

from Orders o,[Order Details] od, Employees e,

Products p, Suppliers s, Customers c

where (o.OrderID = od.OrderID) and

(o.EmployeeID = e.EmployeeID) and

(o.CustomerID = c.CustomerID) and

(od.ProductId = p.ProductID) and

(p.SupplierID = s.SupplierID);

go

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航