就差最后一句不一样,如果不需要对数据集操作,可以把重复的语句赋给一个字符串变量,用EXECUTE执行
if exists (select * from sysobjects where id = object_id('upCritList')) 
    drop procedure upCritList
GO Create procedure upCritList
       @Type int=1,       
       @RecId int=null
as   set nocount off
   
  Declare @sql varchar(500)
  Select @sql = 'Select  top 50
                a.userId 
               ,a.WorkId
               ,isNull(rtrim(c.Title),'''') as Title
               ...
               Left Join (select a.userId,rating = sum(b.rating) 
                            from works a inner join critiques b on a.workId=b.workId
                          group by a.userId) e on a.userId=e.userId '
  if @Type = 1
  begin
    @sql = @sql+'where a.WorkId ='+ @RecId
  end
  else
  begin
    @sql = @sql+'where a.userId ='+ @RecId
  end  Execute(@sql)