这是我的问题的一个简单示例。我有一个创建报告的存储过程。
DECLARE @Report TABLE
(Product VARCHAR(10),
Purchases MONEY default (0)
)
DECLARE @Range TABLE
(minP MONEY,
maxP MONEY,
Descrip VARCHAR(50)
)
INSERT @Range
VALUES(0,1,'0-1'),
(2,5,'2-5'),
(6,10,'6-10')
INSERT @Report(Product, Purchases)
VALUES('A',1),
('A',5),
('B',10)
SELECT r.Product, r.Purchases, x.Descrip
FROM @Report r CROSS JOIN @Range x
WHERE r.purchases BETWEEN x.minp AND x.maxp
结果如下所示:
Product Purchases Descrip
A 1.00 0-1
A 5.00 2-5
B 10.00 6-10
我怎样才能让结果看起来像这样:
Product Purchases Descrip
A 1.00 0-1
A 5.00 2-5
A 0 6-10
B 0 0-1
B 0 2-5
B 10.00 6-10