Wednesday, May 25, 2005

Get all Columns from the Table



create proc GetColumns
@TableName varchar(50)
as
BEGIN
DECLARE @str VARCHAR(8000)
SELECT @str = COALESCE(@str+',','')+
( SELECT COLUMN_NAME as [Column]
FROM INFORMATION_SCHEMA.COLUMNS UM1
WHERE UM1.COLUMN_NAME = UM2.COLUMN_NAME and
UM1.table_name=UM2.table_name
)
FROM INFORMATION_SCHEMA.COLUMNS UM2
where UM2.TABLE_NAME like @TableName

SELECT @str
END

No comments: