SQLSERVER 检查字段值域并输出行数和值列表

select * from 
(
SELECT 
'C_DILEI' as fen,'地类' as fcn,
'NVARCHAR'as ftype,
'2'as flen,
(
SELECT count(1) FROM xbmbd WHERE len(ISNULL(C_DILEI,'')) > 2 
) as rnum,
(
SELECT CAST(C_DILEI AS VARCHAR(50))+',' FROM xbmbd WHERE len(ISNULL(C_DILEI,'')) > 2 GROUP BY C_DILEI ORDER BY C_DILEI for xml path('')
 ) as fval
) t where fval is not null

输出结果如下:

posted on 2015-07-31 22:43  janehlp  阅读(876)  评论(0编辑  收藏  举报