sql存储过程根据传入的参数判断执行哪条SQL语句

我要根据传入的参数判断执行哪条SQL语句!!~

共有1个回答
  • shenzian - 1年前

    面这个存储过程可以满足我们的要求,竟然是Pascal/VB的写法,Begin----End ,不是{},,,对使用C#的我来说,这个语法有点恶心.........

    ALTER PROCEDURE dbo.selectCustomerCNameCount
    @customerID int
    AS
    if @customerID=-1
     begin
     select contentownerid ,userCName,count(*) as countAll from view_usercomment group by contentownerid,userCName order by contentownerid DESC
     end
    else
     begin
     select contentownerid ,userCName,count(*) as countAll from view_usercomment where contentownerid=@customerID group by contentownerid,userCName order by contentownerid DESC
     end