Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 stored proc with dynamic selection

Author  Topic 

thbaig1
Starting Member

8 Posts

Posted - 2011-05-04 : 13:20:43
Hi,
RDBMS : sqlserver 2005
OS : windows


I have to write a stored proc, for given below scenario

Table-A
id
name
col1
col2
col3
...
coln

we add column for some new values. Col1-n will have only status value "1 or 0 ".

Now I want to write a stored proc that should return
id, name and only those col (from col1-n) that have value 1.

I can not hard code col name (col1-n) as in future col can increase, so the stored proc should return always right results.

can you please help me ?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-04 : 14:44:45
Slight problem I foresee: what if col1 has 1 for some rows and 0 for the others?

(That's the slight problem. The rather larger problem is the design of this table.)
Go to Top of Page
   

- Advertisement -