Question : Dynamic Enumerate items procedure

In Microsoft Access I have used a custom function (usually called DList) which would accept the table name, field name, and search criteria as parameters.  It would output a comma seperated list of the values in FieldName from the table where the search criteria is true.

In SQL Server 2000, is there a way to have a stored procedure return the same string output given the same input parameters?

Answer : Dynamic Enumerate items procedure

See stored procedure attached

and use it like this

EXEC Dlist 'yourtable', 'yourcolumn'

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
create procedure Dlist
@table varchar(200),
@column varchar(200)
as
	declare @strSQL nvarchar(2000)
	declare @params nvarchar(2000)
	declare @x1 nvarchar(2000)


	set @strSQL = 'select @x = coalesce(@x + '','', '''') + cast(' + @column + ' as varchar) from ' + @table
	set @params = N'@x varchar(2000) OUTPUT'

	exec sp_executeSQL @strSQL, @params, @x = @x1 OUTPUT

	select @x1
Random Solutions  
 
programming4us programming4us