USE [MyDataBase]
GO
/****** Object: UserDefinedFunction [dbo].[get_columns] Script Date: 4/9/2016 9:20:07 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[get_columns](@table as varchar(MAX))
RETURNS varchar(MAX)
as
begin
declare @ret as varchar(MAX)
select @ret= COALESCE(@ret + ', ', '') + a.name from sys.tables c
join sys.columns a on a.object_id =c.object_id
join sys.types b on a.system_type_id =b.system_type_id
where c.name=@table and a.is_identity<>1 and a.default_object_id =0
ORDER BY A.column_id
return @ret
END