日期:2014-05-17 浏览次数:20441 次
CREATE TABLE TestCount
(
TCID INT IDENTITY PRIMARY KEY,
TNAME VARCHAR(20),
TC1 VARCHAR(20),
TC2 VARCHAR(20),
TC3 VARCHAR(20),
TC4 VARCHAR(20)
)
INSERT INTO TestCount
SELECT '香蕉','A','B','C','D'
UNION ALL
SELECT '苹果','A',NULL,NULL,NULL
UNION ALL
SELECT '大鸭梨',NULL,'B','C','D'
UNION ALL
SELECT '葡萄','A','A','B','D'
UNION ALL
SELECT '桔子','Z','X','A','D'
UNION ALL
SELECT '橙子','H','J','E','F'
select t=substring(t,number,1),ct=count(1) from (select (select isnull(tc1,'')+isnull(tc2,'')+isnull(tc3,'')+isnull(tc4,'') from testcount for xml path('')) as t)tb,master..spt_values where type='p' and number between 1 and len(t) group by substring(t,number,1)