日期:2014-05-18 浏览次数:20705 次
select m.*, s.Name as ShopName from (select '1' as Flag,'更正明細' as name, a.*,b.orderno from (select a.*,b.UserName from ItemsDelete a left join S_User b on a.Deletor = b.UserCode or a.Deletor = b.UserName) a left join orders b on a.orderid=b.id and a.shopid=b.shopid where a.orderid+a.shopid Not in(select id+shopid from OrdersDelete) ) m left join (select [Name], ID from shops order by ID)as s on s.ID = m.shopID
select m.*, s.Name as ShopName from (select '1' as Flag,'更正明細' as name, a.*,b.orderno from (select a.*,b.UserName from ItemsDelete a left join S_User b on a.Deletor = b.UserCode or a.Deletor = b.UserName) a left join orders b on a.orderid=b.id and a.shopid=b.shopid where a.orderid+a.shopid Not in(select id+shopid from OrdersDelete) ) m left join (select [Name], ID from shops)as s on s.ID = m.shopID Union select m.*,s.Name as ShopName from (select '2' as Flag,'刪單明細' as name, a.*,b.orderno from (select a.*,b.UserName from ItemsDelete a left join S_User b on a.Deletor = b.UserCode or a.Deletor = b.UserName) a,OrdersDelete b where a.OrderID=b.ID and a.shopid=b.shopid) m left join Shops s on s.ID=M.ShopID order by shopID,s.id
------解决方案--------------------
select * from ( select top 100 percent m.*, s.Name as ShopName from (select '1' as Flag,'更正明細' as name, a.*,b.orderno from (select a.*,b.UserName from ItemsDelete a left join S_User b on a.Deletor = b.UserCode or a.Deletor = b.UserName) a left join orders b on a.orderid=b.id and a.shopid=b.shopid where a.orderid+a.shopid Not in(select id+shopid from OrdersDelete) ) m left join (select [Name], ID from shops)as s on s.ID = m.shopID order by s.id ) tt Union select * from ( select top 100 percent m.*,s.Name as ShopName from (select '2' as Flag,'刪單明細' as name, a.*,b.orderno from (select a.*,b.UserName from ItemsDelete a left join S_User b on a.Deletor = b.UserCode or a.Deletor = b.UserName) a,OrdersDelete b where a.OrderID=b.ID and a.shopid=b.shopid) m left join Shops s on s.ID=M.ShopID order by shopID ) kk