日期:2014-05-17 浏览次数:20394 次
--> 测试数据:@T
declare @T table([ID] varchar(5),[V1] int,[V2] int,[V3] int)
insert @T
select '00001',2,-1,3 union all
select '00002',3,4,4 union all
select '00003',4,1,27
select 'V1' as Col,min(v1) as [min],MAX(v1) as [max] from @T
union all
select 'V2',min(v2),MAX(v2) from @T
union all
select 'V3',min(v3),MAX(v3) from @T
/*
Col min max
---- ----------- -----------
V1 2 4
V2 -1 4
V3 3 27
*/
DECLARE @a TABLE(ID CHAR(5), V1 INT,V2 INT, V3 INT)
INSERT @a SELECT '00001', 2, -1, 3
union all select '00002', 3, 4, 4
union all select '00003', 4, 1, 27
DECLARE @b TABLE(Col VARCHAR(20),[Min] INT, [MAX] INT)
INSERT @b SELECT 'V1', -2, 1
UNION ALL SELECT 'V2', 2 , &n