SQL 嵌套多层查询

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


--得到XX表的信息,由于许多列都需要绑定D_Type_Detail,所以进行多层嵌套查询
ALTER proc [dbo].[Proc_SelectMateriel]
as
select t3.*,ztd3.TypeDetailName as UseStateName
from
(
 select t4.*,ztd4.TypeDetailName as AssistantUnitName
 from
 (
  select t2.*,ztd2.TypeDetailName as UnitName
  from
  (
   select t1.*,ztd1.TypeDetailName as MaterielAttributeName
   from
   (
    select m.*,r.RoutingName,u.username,mc.MoldClassName
    from dbo.D_Materiel as m
    left join dbo.D_Routing as r
    on m.RoutingID=r.RoutingID
    left join dbo.D_MoldClass as mc
    on m.MoldClassID=mc.MoldClassID
    left join dbo.D_User as u
    on u.UserId=m.AddUserID
   )as t1
   left join dbo.D_Type_Detail as ztd1
   on t1.MaterielAttributeID=ztd1.TypeDetailID
  )as t2
  left join dbo.D_Type_Detail as ztd2
  on t2.UnitID=ztd2.TypeDetailID
 ) as t4
 left join dbo.D_Type_Detail as ztd4
 on t4.AssistantUnitID=ztd4.TypeDetailID
)as t3
left join dbo.D_Type_Detail as ztd3
on t3.UseState=ztd3.TypeDetailID

--exec Proc_SelectMateriel

 

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/rmak2008/archive/2008/12/16/3530682.aspx

转载于:https://www.cnblogs.com/MYGMVP/archive/2009/07/07/1518079.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值