I think I'd do this:
SELECT
c.name AS ColumnName,
t.name + CASE WHEN T.NAME LIKE '%char%'
THEN CASE WHEN C.max_length > 0 THEN '(' + CAST(c.max_length AS VARCHAR(3)) + ')'
ELSE '(max)'
END
WHEN T.NAME LIKE '%binary' AND
C.max_length > 0 THEN '(' + CAST(c.max_length AS VARCHAR(3)) + ')'
ELSE ''
END AS ColumnDataType,
c.precision,
c.scale
FROM
sys.all_columns c
JOIN sys.types t
ON c.user_type_id = t.user_type_id
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question