存储过程,写一个存储过程,一个参数每次执行的时候需要手工输入

fancydong fancydong 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下是之前写的一个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
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
fancydong
MS-SQL Server 34,876 成员 254,635 内容