当前位置: 代码迷 >> Sql Server >> SQL的基础有关问题
  详细解决方案

SQL的基础有关问题

热度:52   发布时间:2016-04-24 09:27:34.0
SQL的基础问题
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE Pre_School_Manage
@zxdm char(6),
@zxmc char(50),
@lb char(1),
@ret char(1) output,
@Str char(10)
AS
BEGIN
   SET NOCOUNT ON;   
   if(@Str='Update')
   begin
      if(exists(select 1 from byqx_xxdm where xxdm=@zxdm))
       begin
     update byqx_xxdm set xxdm=@zxdm,xxmc=@zxmc where xxdm=@zxdm
         if(@@error=0 and @@rowcount<>0) set @ret='1' else set ret='0'
       end
      else set @ret='3'   
   end 
  else if(@Str='Delete')
   begin
    if(exists(select 1 from byqx_xxdm where xxdm=@zxdm))
     begin
  delete from byqx_xxdm where xxdm=@zxdm
      if(@@error=0 and @@rowcount<>0) set @ret='1' else set ret='0'
     end
     else set @ret='3'  
    end
   else  if(@Str='insert')
    begin 
     if(not exists(select 1 from byqx_xxdm where xxdm=@zxdm))
      begin
    insert into byqx_xxdm(xxdm,xxmc,xxzt) values(@zxdm,@zxmc,@lb)
        if(@@error=0 and @@rowcount<>0) set @ret='1' else set ret='0'
      end
     else set @ret='2'
    end 
END
GO

错误:
消息 102,级别 15,状态 1,过程 Pre_School_Manage,第 15 行
'=' 附近有语法错误。
消息 102,级别 15,状态 1,过程 Pre_School_Manage,第 24 行
'=' 附近有语法错误。
消息 102,级别 15,状态 1,过程 Pre_School_Manage,第 33 行
'=' 附近有语法错误。

------解决思路----------------------
替换你的 ,错误在 ret 前没有@符


CREATE PROCEDURE Pre_School_Manage
@zxdm char(6),
@zxmc char(50),
@lb char(1),
@ret char(1) output,
@Str char(10)
AS
BEGIN
   SET NOCOUNT ON;   
   if(@Str='Update')
   begin
      if(exists(select 1 from byqx_xxdm where xxdm=@zxdm))
       begin
     update byqx_xxdm set xxdm=@zxdm,xxmc=@zxmc where xxdm=@zxdm
         if(@@error=0 and @@rowcount<>0) 
set @ret='1' 
else 
set @ret='0'
       end
      else set @ret='3'   
   end 
  else if(@Str='Delete')
   begin
    if(exists(select 1 from byqx_xxdm where xxdm=@zxdm))
     begin
  delete from byqx_xxdm where xxdm=@zxdm
      if(@@error=0 and @@rowcount<>0) set @ret='1' else set @ret='0'
     end
     else set @ret='3'  
    end
   else  if(@Str='insert')
    begin 
     if(not exists(select 1 from byqx_xxdm where xxdm=@zxdm))
      begin
    insert into byqx_xxdm(xxdm,xxmc,xxzt) values(@zxdm,@zxmc,@lb)
        if(@@error=0 and @@rowcount<>0) set @ret='1' else set @ret='0'
      end
     else set @ret='2'
    end 
END
GO


  相关解决方案