日期:2014-05-17 浏览次数:20803 次
--CREATE TABLE huang(订单 INT, 订单明细 int, 数量 int )
--INSERT INTO huang
--SELECT 201101, 20110101 , 1
--UNION ALL
--SELECT NULL ,20110102, 2
--UNION ALL
--SELECT 201102, 20110201 , 1
--UNION ALL
--SELECT NULL ,20110202 , 3
WITH cte
AS ( SELECT ROW_NUMBER() OVER ( ORDER BY GETDATE() ) id ,
*
FROM Huang
),
cte1
AS ( SELECT *
FROM cte
WHERE id = 1
UNION ALL
SELECT b.id ,
CASE WHEN b.订单 IS NULL THEN a.订单
ELSE b.订单
END 订单 ,
b.订单明细 ,
b.数量
FROM &n