Get Columns From SP!

A

Arpan

An ASP application needs to display DISTINCT records of all the columns
existing in a SQL Server DB table in different drop-down lists. The
column names & the no. of columns aren't known while coding. The no. of
drop-downs depend on the no. of columns i.e. if the DB table has 10
columns, there should be 10 drop-downs. This is the stored procedure I
have written to do this:

----------------------------------------
CREATE PROCEDURE GetRecords
AS
DECLARE
@ordpos int,
@colname sysname,
@sql varchar(8000)

SET @ordpos=1

WHILE @ordpos<=(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_NAME='MyTable')
BEGIN
SELECT @colname=COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_NAME='MyTable' AND ORDINAL_POSITION=@ordpos
SET @sql='SELECT DISTINCT(' + @colname + ') FROM MyTable ORDER BY ' +
@colname
EXEC(@sql)
SET @ordpos=@ordpos+1
END
----------------------------------------

As such, the above stored procedure works fine when executed in the
Query Analyzer but the problem is in populating the drop-downs in the
ASP page. Since the stored procedure generates the column names
dynamically, I don't know the column names while coding the different
drop-downs.

How do I populate the drop-downs? Note that I want the name of the
individual drop-downs to be the name of the column.

Thanks,


Arpan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top