alter proc my_testproc
@id int,
  @s   char(10) ='c'  output
with encryption
as
set @s=case @id
 when 1 then  select aa from aaa where id='1'
end
go
我做了一个存储过程,想在里面用CASE 但他符合条件时会执行相应的SQL 语句,但
报"在关键字 'select' 附近有语法错误。在关键字 'end' 附近有语法错误。"
我着急,哪位高手帮忙解决一下.

解决方案 »

  1.   

    set @s=case @id when 1 then  (select aa from aaa where id='1') end
      

  2.   

    alter proc my_testproc
    @id int,
      @s   char(10) ='c'  output
    with encryption
    as
    set @s=case @id
     when 1 then  (select aa from aaa where id='1')
    end
    go
    加个括号,楼上的是对的
      

  3.   

    alter proc my_testproc
    @id int,
      @s   char(10) ='c'  output
    with encryption
    as
    set @s=case @id
     when 1 then ( select aa from aaa where id=@id)
    end
    go