drop procedure p_tt
go
create procedure p_tt
(
@s varchar(50)
)
as
declare @s1 varchar(500)
select @s1='select Pid'
select @s1=@s1+','+[name] from syscolumns where charindex(','+convert(varchar,colid)+',',@s)>0 and id=(select id from sysobjects where name='t_we_station' and type='U')
select @s1=@s1+' from t_we_station'
exec(@s1)
exec p_tt ',2,3,4,5,5,5'
上面的Pid是我表里面的第一个字段,t_we_station是我的表名,colid是系统表的列名,对应你说的1-20,我上面的写的可以实现动态的查询,
但是有一些限制,不过应该可以给楼主一些思路。