存储过程,写一个存储过程,一个参数每次执行的时候需要手工输入
以下是之前写的一个SQL语句,现在需要把这个语句写成存储进程
第二段插入明细数据和第三段更改值中的card_type = @card_type,需要每次执行这个存储进程的时候作为入参,需要操作者或者程序调用的时候传值过来
use testxx
go
/******************************备份原始表******************************************/
declare @table_no varchar(120)
select @table_no = 'bak'+replace(replace(replace(convert(char(19),getdate(),121),'-',''),':',''),' ','')
--select @table_no
DECLARE @sql NVARCHAR(MAX)
SET @sql='select * into ['+@table_no+'] from t_rm_vip_info'
EXEC (@sql);
/*****************************插入明细数据*******************************************/
---select * from t_rm_vip_info where dbo.f_get_descry_star(residual_amt) >10
---select card_id,dbo.f_get_descry_star(residual_amt) from t_rm_vip_info where dbo.f_get_descry_star(residual_amt) >10
use testxx
go
declare @card_type varchar(120)
set @card_type = '01'
insert into t_rm_saving_plus_record
(branch_no,card_id,plus_count,oper_id ,oper_date,old_count,
num1,other1,residual_amt,com_flag,plus_real_count,real_date,pay_way)
select '000',card_id, (10-dbo.f_get_descry_star(residual_amt)) as plus_count ,'1001',getdate(),dbo.f_get_descry_star(residual_amt),
'0','自动清除','0','0',(10-dbo.f_get_descry_star(residual_amt)) ,null,'RMB'
from t_rm_vip_info
where dbo.f_get_descry_star(residual_amt) >10 and card_type = @card_type
/*****************************更改值*******************************************/
update t_rm_vip_info set residual_amt = '<:66420.-' where dbo.f_get_descry_star(residual_amt) >10 and card_type = @card_type
go
第二段插入明细数据和第三段更改值中的card_type = @card_type,需要每次执行这个存储进程的时候作为入参,需要操作者或者程序调用的时候传值过来
use testxx
go
/******************************备份原始表******************************************/
declare @table_no varchar(120)
select @table_no = 'bak'+replace(replace(replace(convert(char(19),getdate(),121),'-',''),':',''),' ','')
--select @table_no
DECLARE @sql NVARCHAR(MAX)
SET @sql='select * into ['+@table_no+'] from t_rm_vip_info'
EXEC (@sql);
/*****************************插入明细数据*******************************************/
---select * from t_rm_vip_info where dbo.f_get_descry_star(residual_amt) >10
---select card_id,dbo.f_get_descry_star(residual_amt) from t_rm_vip_info where dbo.f_get_descry_star(residual_amt) >10
use testxx
go
declare @card_type varchar(120)
set @card_type = '01'
insert into t_rm_saving_plus_record
(branch_no,card_id,plus_count,oper_id ,oper_date,old_count,
num1,other1,residual_amt,com_flag,plus_real_count,real_date,pay_way)
select '000',card_id, (10-dbo.f_get_descry_star(residual_amt)) as plus_count ,'1001',getdate(),dbo.f_get_descry_star(residual_amt),
'0','自动清除','0','0',(10-dbo.f_get_descry_star(residual_amt)) ,null,'RMB'
from t_rm_vip_info
where dbo.f_get_descry_star(residual_amt) >10 and card_type = @card_type
/*****************************更改值*******************************************/
update t_rm_vip_info set residual_amt = '<:66420.-' where dbo.f_get_descry_star(residual_amt) >10 and card_type = @card_type
go
...全文
相关推荐
Sql Server 存储过程调用存储过程接收输出参数返回值
主要介绍了Sql Server 存储过程调用存储过程接收输出参数返回值,需要的朋友可以参考下
Python中执行存储过程及获取存储过程返回值的方法
主要介绍了Python中执行存储过程及获取存储过程返回值的方法,结合实例形式总结分析了Python调用存储过程的常用方法与相关操作注意事项,需要的朋友可以参考下
MySQL 存储过程中执行动态SQL语句的方法
drop PROCEDURE if exists my_procedure; create PROCEDURE my_procedure() BEGIN declare my_sqll varchar(500); set my_sqll='select * from aa_list'; set @ms=my_sqll; PREPARE s1 from @ms; EXECUTE s1; deallocate prepare s1; end; 您可能感兴趣的文章:mysql 存储过程中变量的定义与赋值操作mysql存储过程详解mysq
mysql 存储过程输入输出参数示例
创建存储过程时可以输入输出参数,下面是一个mysql存储过程的创建示例,需要的朋友可以参考下
mysql 动态执行存储过程语句
MSSQL中动态执行sql语句可以使用EXEC()函数。MSSQL中也有类似的函数EXECUTE(),不过不同的是MYSQL中动态执行存储过程语句与MSSQL还是有区别的。


