Technical Article

Generate Column Listing

,

Returns an ordered column listing for the specified table, stored procedure, or view.

DECLARE @ObjectName varchar(128)

SET @ObjectName = 'myTable'

SELECTCONVERT(varchar(64),
sc.name + ' ' +
st.name +
CASE sc.typestat
WHEN 2 THEN '(' + CONVERT(varchar, sc.length) + ')'
ELSE ''
END
)
FROMsyscolumns sc
JOINsystypes st ON(sc.xtype = st.xtype)
WHEREsc.id = OBJECT_ID(@ObjectName)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating