本文介绍了请在授权时更正代码显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 创建 table tbl_cyl_gas_master ( serial_no int , gas_name varchar ( 50 ), tran_stat varchar ( 50 )) alter procedure gas ( @ action varchar ( 20 ), @ serial_no int , @ gas_name varchar ( 50 ), @ tran_stat varchar ( 50 )) as 开始 选择 @ tran_stat =( CASE WHEN @ action = ' ADD' 然后 ' FR' 何时 @ action = ' 更新' 然后 ' FR' @ action = ' 授权' 然后 ' AU' else ' DE' end ) - 声明@trannew varchar(10), if @ action = ' 添加' 开始 插入 进入 tbl_Cyl_gas_master 值( @ gas_name , @ tran_stat ) end else if @行动= ' 更新' 开始 如果 @ tran_stat == ' FR'&& @serial_no == @ serial_no update tbl_Cyl_gas_master set gas_name = @ gas_name 其中 serial_no = @ serial_no else RAISERROR (' 交易不是新鲜的', 16 , 1 ); end else if @ action = ' 授权' 开始 - 从tbl_cyl_gas_master中选择@tran_stat,其中serial_no = @ serial_no 如果 @ tran_stat = ' FR' update tbl_Cyl_gas_master set tran_stat = @ tran_stat 其中 serial_no = @ serial_no else RAISERROR (' 交易已授权', 16 , 1 ) 结束 else delete gas_name 来自 tbl_Cyl_gas_master 其中 serial_no = @ serial_no 结束 解决方案 代码修改很少: 试试这个 CREATE程序gas ( @action varchar(20), @serial_no int, @gas_name varchar(50), @tran_stat varchar(50)) as begin select @tran_stat =(CASE WHEN @ action ='ADD'then'FR '@ action ='更新',然后是'FR',当@ac时tion ='授权'然后'AU'其他'DE'结束) --declare @trannew varchar(10), if @ action ='Add' begin 插入tbl_Cyl_gas_master(gas_name,tran_stat)值(@ gas_name,@ tran_stat)结束否则如果@ action ='更新'开始如果((@tran_stat ='FR')AND(@ serial_no = @ serial_no)) update tbl_Cyl_gas_master set gas_name = @ gas_name其中serial_no = @ serial_no else RAISERROR('交易不是新鲜的,16,1); 结束否则如果@ action ='授权'开始如果@tran_stat ='FR'更新tbl_Cyl_gas_master set tran_stat = @ tran_stat其中serial_no = @ serial_no else RAISERROR('交易已经授权',16,1)结束否则从tbl_Cyl_gas_master删除gas_name其中serial_no = @ serial_no 结束 GO 替换此行: 如果 @ tran_stat == ' FR'&& @serial_no == @ serial_no 这个: if ( @ tran_stat = ' FR' 和 @ serial_no = @ serial_no ) 此行: 插入 进入 tbl_Cyl_gas_master 值( @ gas_name , @ tran_stat ) 这个: 插入 into tbl_Cyl_gas_master(gas_name,tran_stat) values ( @ gas_name , @tran_stat ) create table tbl_cyl_gas_master(serial_no int,gas_name varchar(50),tran_stat varchar(50))alter procedure gas(@action varchar(20),@serial_no int,@gas_name varchar(50),@tran_stat varchar(50))asbegin select @tran_stat =(CASE WHEN @action='ADD' then 'FR' when @action='Update' then 'FR' when @action='Authorise' then 'AU' else 'DE' end ) --declare @trannew varchar(10), if @action='Add' begin insert into tbl_Cyl_gas_master values (@gas_name,@tran_stat) endelse if @action='Update' begin if @tran_stat == 'FR' && @serial_no==@serial_no update tbl_Cyl_gas_master set gas_name=@gas_name where serial_no=@serial_no else RAISERROR ('Transaction not is fresh',16,1); endelse if @action='Authorise' begin --select @tran_stat from tbl_cyl_gas_master where serial_no=@serial_no if @tran_stat = 'FR' update tbl_Cyl_gas_master set tran_stat=@tran_stat where serial_no=@serial_no else RAISERROR ('Transaction already Authorised',16,1) endelse delete gas_name from tbl_Cyl_gas_master where serial_no=@serial_no end 解决方案 Little modifications in your code:Try thisCREATE procedure gas(@action varchar(20),@serial_no int,@gas_name varchar(50),@tran_stat varchar(50))asbeginselect @tran_stat =(CASE WHEN @action='ADD' then 'FR' when @action='Update' then 'FR' when @action='Authorise' then 'AU'else 'DE' end )--declare @trannew varchar(10),if @action='Add'begininsert into tbl_Cyl_gas_master(gas_name,tran_stat) values (@gas_name,@tran_stat)endelse if @action='Update'beginif ((@tran_stat = 'FR') AND (@serial_no=@serial_no))update tbl_Cyl_gas_master set gas_name=@gas_name where serial_no=@serial_noelseRAISERROR ('Transaction not is fresh',16,1);endelse if @action='Authorise'beginif @tran_stat = 'FR'update tbl_Cyl_gas_master set tran_stat=@tran_stat where serial_no=@serial_noelseRAISERROR ('Transaction already Authorised',16,1)endelsedelete gas_name from tbl_Cyl_gas_master where serial_no=@serial_noendGOHi,Replace this line:if @tran_stat == 'FR' && @serial_no==@serial_nowith this:if (@tran_stat = 'FR' and @serial_no = @serial_no)and this line:insert into tbl_Cyl_gas_master values (@gas_name,@tran_stat)with this:insert into tbl_Cyl_gas_master (gas_name, tran_stat) values (@gas_name, @tran_stat) 这篇关于请在授权时更正代码显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 12:44