FUNCTION TO concatenate all COLUMNS OF a TABLE
GO
CREATE FUNCTION fn_columns( @tblname varchar(50))
returns varchar(MAX)
as
BEGIN
DECLARE @name VARCHAR(500)=''
SELECT @name=name+', '+@name FROM SYS.columns WHERE OBJECT_ID=OBJECT_ID(@tblname)
RETURN left(@NAME,len(@NAME)-1)
END
SELECT NAME,dbo.fn_columns(name)as COLUMNS from sys.tables
No comments:
Post a Comment