存储过程如何根据不同选择执行不同的查询条件,例如选择字段为A,执行一段查询条件,为B,执行另一段查询条件ALTER proc . @produceline varchar(10), @workproc varchar(20), @finishid varchar(30), @auitdate datetime, @abtype varchar(10)asdeclare @sql varchar(1000)begin set @sql='select SUM(RpTotalNums) as 投料数 from .. where ' + 'RpProduceLine = ' + cast(@produceline as varchar) + 'AND RpWorkproc = ' + cast(@workproc as varchar) + 'AND RpFinishID = ' + cast(@finishid as varchar) + 'AND RpAuditStatus = 1 and RpAuditDate between convert(varchar(10),DATEADD(dd,0,'+cast(@auitdate as varchar)+'),120)+07:00 and convert(varchar(10),DATEADD(dd,1,'+cast(@auitdate as varchar)+'),120)+07:00 ' if (@abtype= 'A') begin set @sql=@sql+' and RpABMaterial = ''A'' and CHARINDEX(''_'',RpERPWorkOrder)=0 ' end else if (@abtype= 'B') begin set @sql=@sql+' and RpABMaterial = ''B'' ' end else if (@abtype= '返花') begin set @sql=@sql+' and CHARINDEX(''_'',RpERPWorkOrder)>0 and RpABMaterial = ''A'' ' end else begin set @sql=@sql+' and RpAuditStatus = 1 ' end exec (@sql)end