关闭

近几天使用到多张表合成一张表、时间转化笔记。

136人阅读 评论(0) 收藏 举报
分类:
SELECT 
	*
FROM 	
	(
		SELECT o.OrderNo, o.OrderDate,o.CheckReason FROM Orders o
		WHERE OrderDate BETWEEN '2015-09-01 14:33:29.802' AND '2015-11-07 14:33:29.802' 
		AND OrderStatus = '-30' 
	) t1 OUTER APPLY(
		SELECT PName = STUFF(REPLACE(REPLACE((
			SELECT PName FROM
			(
				SELECT s.OrderNo,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-09-01 14:33:29.802'	
				AND '2015-11-07 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-09-01 14:33:29.802'	
				AND '2015-11-07 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-09-01 14:33:29.802'	
				AND '2015-11-07 14:33:29.802'  
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-09-01 14:33:29.802'	
				AND '2015-11-07 14:33:29.802' 
			) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO
		),'<t2 PName="',','),'"/>',''),1,1,'')
	)N

SELECT * FROM (
SELECT *
FROM 	
	(
		SELECT o.OrderDate, o.DeliveryDate,o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent 
		FROM Orders o
		WHERE OrderDate BETWEEN '2015-11-16 14:33:29.802' AND '2015-11-18 14:33:29.802'  AND DeliveryDate <='2015-11-23 14:33:29.802'
	) t1 OUTER APPLY(
		SELECT PName = STUFF(REPLACE(REPLACE((
			SELECT PName,面料,米数 FROM
			(
				SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802'  
				UNION ALL
				SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
			) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO
		),'<t2 PName=',','),'/>',''),1,1,'')
	)N
	)t3 
WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N''

SELECT * FROM (
SELECT *
FROM 	
	(
		SELECT o.OrderNo, o.CreateTime,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent 
		FROM Orders o
		WHERE OrderDate BETWEEN '2015-11-16 14:33:29.802' AND '2015-11-18 14:33:29.802'  AND DeliveryDate <='2015-11-23 14:33:29.802'
	) t1 OUTER APPLY(
		SELECT PName = STUFF(REPLACE(REPLACE((
			SELECT PName,面料,米数 FROM
			(
				SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802'  
				UNION ALL
				SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
			) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO
		),'<t2 PName=',','),'/>',''),1,1,'')
	)N
	)t3 
WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N''


SELECT * FROM (
SELECT *
FROM 	
	(
		SELECT o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent 
		FROM Orders o
		WHERE OrderDate BETWEEN '{0}' AND '{1}' AND DeliveryDate <= '{2}'
	) t1 OUTER APPLY(
		SELECT PName = STUFF(REPLACE(REPLACE((
			SELECT PName,面料,米数,工艺 FROM
			(
				SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,Technology 工艺, CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID
				AND OrderDate BETWEEN '{3}'
				AND '{4}'
				UNION ALL
				SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID
				AND OrderDate BETWEEN '{5}'
				AND '{6}'
				UNION ALL
				SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID
				AND OrderDate BETWEEN '{7}'
				AND '{8}'
				UNION ALL
				SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID
				AND OrderDate BETWEEN '{9}'	
				AND '{10}'
			) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO
		),'<t2 PName=',','),'/>',''),1,1,'')
	)N
	)t3 
WHERE t3.PName is not null and t3.PName <>N''



select s.OrderNo,
       h.Fabric,
	   h.MaterialUnit, 
	   case s.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent , 
	   h.Technology,
	   h.Quantity 
from Orders s join OrdersCoats h on h.OrderID =s.OrderID 
where s.OrderDate between '2015-11-16 14:33:29.802'and '2015-11-18 14:33:29.802'  and s.OrderStatus ='90' and s.DeliveryDate <='2015-11-24 14:33:29.802' and s.OrderNo <>N'' and h.Technology <>N'' 
order by s.DeliveryDate desc 


SELECT * FROM (SELECT * FROM (SELECT o.OrderDate, o.DeliveryDate,o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent  FROM Orders o	WHERE OrderDate BETWEEN '2015/10/1 11:41:01' AND '2015/11/18 11:41:01'  AND DeliveryDate <= '2015-11-18 11:43:02.734' 	) t1 OUTER APPLY(	SELECT PName = STUFF(REPLACE(REPLACE((	SELECT PName,面料,米数 FROM	(	SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID	AND OrderDate BETWEEN '2015/10/1 11:41:01'	AND '2015/11/18 11:41:01'UNION ALL	SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID	AND OrderDate BETWEEN '2015/10/1 11:41:01'	AND '2015/11/18 11:41:01'	UNION ALL	SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID	AND OrderDate BETWEEN '2015/10/1 11:41:01'	AND '2015/11/18 11:41:01' 	UNION ALL	SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID	AND OrderDate BETWEEN '2015/10/1 11:41:01'	AND '2015/11/18 11:41:01'	) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO	),'<t2 PName=',','),'/>',''),1,1,''))N	)t3  WHERE t3.PName is not null and t3.PName <>N'' 

select s.OrderNo, h.Fabric, h.MaterialUnit,  case s.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent ,  h.Technology,h.Quantity from Orders s join OrdersCoats h on h.OrderID =s.OrderID  where s.OrderDate between '{0}'and '{1}'  and s.OrderStatus ='90' and s.DeliveryDate <='{2}' and s.OrderNo <>N'' and h.Technology <>N'' order by s.DeliveryDate desc  

insert into ShirtSize(ShirtOrderNo,ShirtCustomerName,ShirtCustomerSource,ShirtCustomerHeight,ShirtCustomerWeight,ShirtClothesLength,ShirtShoulder,ShirtOutsideSleeve,ShirtBust,Abdomen,NeckLine)values('" + Convert.ToString(txtShirtOrderNo.Text) + "','" + Convert.ToString(txtShirtCustomerName.Text) + "','" + Convert.ToString(txtShirtCustomerSource.Text) + "','" + Convert.ToString(txtShirtCustomerHeight.Text) + "','" + Convert.ToString(txtShirtCustomerWeight.Text) + "','" + Convert.ToString(txtShirtClothesLength.Text) + "','" + Convert.ToString(txtShirtShoulder.Text) + "','" + Convert.ToString(txtShirtOutsideSleeve.Text) + "','" + Convert.ToString(txtShirtBust.Text) + "','" + Convert.ToString(txtAbdomen.Text) + "','" + Convert.ToString(txtNeckLine.Text) + "')


select s.OrderDate,
       s.DeliveryDate,
	   s.OrderNo,
       case s.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent,
	   c.ProductName,
	   c.Quantity ,
	   c.Fabric,
	   c.MaterialUnit 
from Orders s join OrdersCoats c on s.OrderID =c.OrderID  
where   s.OrderDate between '2015-11-01 14:33:29.802'and '2015-11-07 14:33:29.802' 
        and s.DeliveryDate <='2015-11-07 14:33:29.802' and c.ProductName <>N'' 
		and s.OrderNo <>N''
order by s.DeliveryDate desc 

SELECT * FROM (SELECT * FROM (SELECT o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent FROM Orders o WHERE OrderDate BETWEEN '2015/11/16 15:06:43' AND '2015/11/16 15:06:43' and OrderStatus ='90'	) t1 OUTER APPLY(	SELECT PName = STUFF(REPLACE(REPLACE((	SELECT PName,面料,米数,工艺 FROM	(	SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,Technology 工艺, CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID AND OrderDate BETWEEN '2015/11/16 15:06:43' AND '2015/11/16 15:06:43'	UNION ALL	SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID	AND OrderDate BETWEEN '2015/11/16 15:06:43'	AND '2015/11/16 15:06:43'UNION ALL	SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID	AND OrderDate BETWEEN '2015/11/16 15:06:43'	AND '2015/11/16 15:06:43'	UNION ALL	SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID	AND OrderDate BETWEEN '2015/11/16 15:06:43'	AND '2015/11/16 15:06:43'	) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO ),'<t2 PName=',','),'/>',''),1,1,'')	)N	)t3  WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N'' 

SELECT * FROM (SELECT * FROM (SELECT o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent FROM Orders o WHERE OrderDate BETWEEN '2015-11-17 00:00:00' AND '2015-11-17 23:59:59' and OrderStatus ='90'	) t1 OUTER APPLY(	SELECT PName = STUFF(REPLACE(REPLACE((	SELECT PName,面料,米数,工艺 FROM	(	SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,Technology 工艺, CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID AND OrderDate BETWEEN '2015-11-17 00:00:00' AND '2015-11-17 23:59:59'	UNION ALL	SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-17 00:00:00'	AND '2015-11-17 23:59:59'UNION ALL	SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-17 00:00:00'	AND '2015-11-17 23:59:59'	UNION ALL	SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-17 00:00:00'	AND '2015-11-17 23:59:59'	) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO ),'<t2 PName=',','),'/>',''),1,1,'')	)N	)t3  WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N'' 

select *
from Orders
where OrderNo='ZQ001001'
select *
from OrdersSuits
where OrderID ='188'


DELETE FROM Orders WHERE OrderNo='ZF930006'  





select 
distinct
o.OrderID, 
o.TranNo, 
o.OrderNo, 
c.CustomerName, 
o.Amount, 
e.EmployeeName, 
o.OrderDate, 
o.DeliveryDate, 
o.OrderStatus
from  
orders o,
customer c,
OAAccount a,
Employee e ,
OrderStatusRecord osr
where 
o.isdelete=0
and c.id=o.customerid
and o.Creater=a.AccountID 
and a.UserID=e.EmployeeID 
and o.OrderID=osr.OrderID
and osr.OrderStatus=110
and osr.NewStatus=90
and osr.CreateTime between '2015/9/20 0:00:00' and '2015/11/22 0:00:00'

SELECT * FROM (
SELECT *
FROM 	
	(
		SELECT o.OrderNo ,convert(char(10),o.CreateTime,120) as CreateTime,r.Remark,DateDiff( DAY,r.CreateTime,o.DeliveryDate)AS Day  
		FROM Orders o  join  OrderStatusRecord r on r.OrderID=o.OrderID
		WHERE  o.OrderDate BETWEEN '2015-11-16 14:33:29.802' AND '2015-11-18 14:33:29.802'  
	) t1 OUTER APPLY(
		SELECT PName = STUFF(REPLACE(REPLACE((
			SELECT PName FROM
			(
				SELECT s.OrderNo,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802'  
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID
				AND OrderDate BETWEEN '2015-11-16 14:33:29.802'	
				AND '2015-11-18 14:33:29.802' 
			) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO
		),'<t2 PName=',','),'/>',''),1,1,'')
	)N
	)t3 
WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N'' order by t3.Day desc


SELECT * FROM (
SELECT *
FROM 	
	(
		SELECT o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent 
		FROM Orders o
		WHERE OrderDate BETWEEN '{0}' AND '{1}' AND DeliveryDate <= '{2}'
	) t1 OUTER APPLY(
		SELECT PName = STUFF(REPLACE(REPLACE((
			SELECT PName,面料,米数,工艺 FROM
			(
				SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,Technology 工艺, CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID
				AND OrderDate BETWEEN '{3}'
				AND '{4}'
				UNION ALL
				SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID
				AND OrderDate BETWEEN '{5}'
				AND '{6}'
				UNION ALL
				SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID
				AND OrderDate BETWEEN '{7}'
				AND '{8}'
				UNION ALL
				SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID
				AND OrderDate BETWEEN '{9}'	
				AND '{10}'
			) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO
		),'<t2 PName=',','),'/>',''),1,1,'')
	)N
	)t3 
WHERE t3.PName is not null and t3.PName <>N''

SELECT * FROM (

SELECT *
FROM 	
	(
		SELECT o.OrderNo ,o.CreateTime ,r.Remark,DateDiff( DAY,r.CreateTime,o.DeliveryDate)AS Day  
		FROM Orders o  join  OrderStatusRecord r on r.OrderID=o.OrderID
		WHERE  o.OrderDate BETWEEN '{0}' AND '{1}' 
	) t1 OUTER APPLY(
		SELECT PName = STUFF(REPLACE(REPLACE((
			SELECT PName FROM
			(
				SELECT s.OrderNo,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID
				AND OrderDate BETWEEN '{2}'
				AND '{3}'
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID
				AND OrderDate BETWEEN '{4}'
				AND '{5}'
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID
				AND OrderDate BETWEEN '{6}'
				AND '{7}'
				UNION ALL
				SELECT s.OrderNo,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID
				AND OrderDate BETWEEN '{8}'
				AND '{9}'
			) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO
		),'<t2 PName=',','),'/>',''),1,1,'')
	)N
	)t3 
WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N''

SELECT * FROM (SELECT * FROM (SELECT o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent FROM Orders o WHERE OrderDate BETWEEN '2015-11-15 00:00:00' AND '2015-11-19 23:59:59' and OrderStatus ='90'	) t1 OUTER APPLY(	SELECT PName = STUFF(REPLACE(REPLACE((	SELECT PName,面料,米数,工艺 FROM	(	SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,Technology 工艺, CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID AND OrderDate BETWEEN '2015-11-15 00:00:00' AND '2015-11-19 23:59:59'	UNION ALL	SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-15 00:00:00'	AND '2015-11-19 23:59:59'UNION ALL	SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-15 00:00:00'	AND '2015-11-19 23:59:59'	UNION ALL	SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-15 00:00:00'	AND '2015-11-19 23:59:59'	) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO ),'<t2 PName=',','),'/>',''),1,1,'')	)N	)t3  WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N''  order by t3.IsCustomerUrgent desc

select o.OrderNo ,o.CreateTime ,r.Remark,DateDiff( DAY,r.CreateTime,o.DeliveryDate)  

from   Orders o  join  OrderStatusRecord r on r.OrderID=o.OrderID

select *
from Orders 
where OrderStatus =50 and CreateTime BETWEEN '2015-11-20 00:00:00'	AND '2015-11-20 23:59:59'

select convert(char(10),CreateTime,120) 
from Orders 

SELECT * FROM (SELECT * FROM (SELECT convert(char(10),o.OrderDate,120) as OrderDate , convert(char(10),o.DeliveryDate,120) as DeliveryDate ,o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent  FROM Orders o	WHERE OrderDate BETWEEN '2015-11-15 00:00:00' AND '2015-11-20 23:59:59'  AND DeliveryDate <= '2015-11-20 16:15:47.357' 	) t1 OUTER APPLY(	SELECT PName = STUFF(REPLACE(REPLACE((	SELECT PName,面料,米数 FROM	(	SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-15 00:00:00'	AND '2015-11-20 23:59:59'UNION ALL	SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-15 00:00:00'	AND '2015-11-20 23:59:59'	UNION ALL	SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-15 00:00:00'	AND '2015-11-20 23:59:59' 	UNION ALL	SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-15 00:00:00'	AND '2015-11-20 23:59:59'	) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO	),'<t2 PName=',','),'/>',''),1,1,''))N	)t3  WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N'' 


SELECT * FROM (SELECT * FROM (SELECT o.OrderNo,case o.IsCustomerUrgent when 0 then N'不加急' when 1 then N'加急' END as IsCustomerUrgent FROM Orders o WHERE OrderDate BETWEEN '2015-11-19 00:00:00' AND '2015-11-19 23:59:59' and OrderStatus ='90'	) t1 OUTER APPLY(	SELECT PName = STUFF(REPLACE(REPLACE((	SELECT PName,面料,米数,工艺 FROM	(	SELECT s.OrderNo,u.Fabric 面料 ,u.MaterialUnit 米数,Technology 工艺, CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID AND OrderDate BETWEEN '2015-11-19 00:00:00' AND '2015-11-19 23:59:59'	UNION ALL	SELECT s.OrderNo,p.Fabric 面料,p.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-19 00:00:00'	AND '2015-11-19 23:59:59'UNION ALL	SELECT s.OrderNo,v.Fabric 面料,v.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-19 00:00:00'	AND '2015-11-19 23:59:59'	UNION ALL	SELECT s.OrderNo,c.Fabric 面料,c.MaterialUnit 米数,Technology 工艺,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-19 00:00:00'	AND '2015-11-19 23:59:59'	) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO ),'<t2 PName=',','),'/>',''),1,1,'')	)N	)t3  WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N'' order by t3.IsCustomerUrgent desc 

SELECT * FROM ( SELECT * FROM (	SELECT o.OrderNo , convert(char(10),o.CreateTime,120) as OrderDate  ,r.Remark,DateDiff( DAY,r.CreateTime,o.DeliveryDate)AS Day   FROM Orders o  join  OrderStatusRecord r on r.OrderID=o.OrderID	WHERE  o.OrderDate BETWEEN '2015-11-18 00:00:00' AND '2015-11-20 23:59:59'	) t1 OUTER APPLY( SELECT PName = STUFF(REPLACE(REPLACE((	SELECT PName FROM(	SELECT s.OrderNo,CONVERT(nvarchar(10),u.Quantity)+N'套'+u.ProductName PName FROM Orders s, OrdersSuits u WHERE u.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-18 00:00:00'	AND '2015-11-20 23:59:59'	UNION ALL	SELECT s.OrderNo,CONVERT(nvarchar(10),p.Quantity)+N'套'+p.ProductName PName FROM Orders s, OrdersPants p WHERE p.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-18 00:00:00'	AND '2015-11-20 23:59:59'	UNION ALL	SELECT s.OrderNo,CONVERT(nvarchar(10),v.Quantity)+N'套'+v.ProductName PName FROM Orders s, OrdersVest v WHERE v.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-18 00:00:00'	AND '2015-11-20 23:59:59'	UNION ALL	SELECT s.OrderNo,CONVERT(nvarchar(10),c.Quantity)+N'套'+c.ProductName PName FROM Orders s, OrdersCoats c WHERE c.OrderID = s.OrderID	AND OrderDate BETWEEN '2015-11-18 00:00:00'	AND '2015-11-20 23:59:59'	) t2 WHERE t2.OrderNo=t1.OrderNo FOR XML AUTO	),'<t2 PName=',','),'/>',''),1,1,'')	)N	)t3  WHERE t3.PName is not null and t3.PName <>N'' and t3.OrderNo is not null  and t3.OrderNo <>N''order by t3.Day desc 

select convert(char(10),s.OrderDate,120) as OrderDate ,s.OrderNo,c.Monogram,c.Quantity  from Orders s join OrdersCoats c on c.OrderID =s.OrderID   where s.OrderDate between '2015-10-01 00:00:00'and '2015-11-20 23:59:59' and c.Monogram is not null  and c.Monogram <>N'' and  c.ProductName ='上衣' order by s.OrderDate  desc


1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8507次
    • 积分:379
    • 等级:
    • 排名:千里之外
    • 原创:29篇
    • 转载:8篇
    • 译文:0篇
    • 评论:0条
    文章分类