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

时间:2023-01-21 16:41:14
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

输出结果如下:

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