• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
雪飞夏日
博客园    首页    新随笔    联系   管理    订阅  订阅
SQL Server中Insert与Select的组合使用
SQL Server中有示例数据库Northwind。新建表Sales用于存储销售信息,字段为EmployeeID,ProductID,SupplierID,CustomerID,OrderDate,UnitPrice,Total,Quantity,Discount。   下面的语句从Orders,Order Details, Employees,Products, Suppliers, Customers表选择相应的
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//批处理的标志
posted on 2009-07-27 18:34  雪飞夏日  阅读(992)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3