Grouped results with SQL Server Stored Procedures
Is it possible to generate results as shown in the at开发者_如何学Gotachment using SQL server 2008 Stored Procedures?
you can user a SELECT to have what you showed:
SELECT vendor,
category,
sub_category,
product,
price,
vendor_name
FROM (
SELECT vendor AS ID,
NULL AS vendor,
category,
sub_category,
product,
price,
vendor_name
FROM table
UNION ALL
SELECT DISTINCT vendor AS ID,
vendor,
NULL AS category,
NULL AS sub_category,
NULL AS product,
NULL AS price,
NULL AS vendor_name
FROM table
) T
ORDER BY ID, category
精彩评论