CREATE PROCEDURE Webn_Product_GetListSingleMember @hcid int, @shownum int, @scid int AS declare @sql nvarchar(1000) if @scid=0 set @sql='select top '+str(@shownum)+' * from products t where productid=(select max(productid) from products where memberid=t.memberid) and hcid='+str(@hcid)+' order by productid desc' else set @sql='select top '+str(@shownum)+' * from products t where productid=(select max(productid) from products where memberid=t.memberid) and hcid='+str(@hcid)+' and scid='+str(@scid)+' order by productid desc' --print(@sql) exec(@sql) GO