Sql验证exists、print

下面是一个普通的查询,
其中包括了关键字exists、print的用法;
Exists –验证是否重复,重复返回-1,修改成功返回1
< > – 不等于
And – 并且
Or – 或者
Print – 返回提示
commit tran –提交事务 确保执行的完整性
begin tran –开始事务
rollback tran –回滚事务
@@error --全局变量,返回一些标志码 比如:commit tran返回0,rollback tran返回非0;

代码如下:
if(@type=‘Click_UpdateStaff’)
if exists(Select 0 from t_staff where staff_id <> @staff_id and t_staff.staff_number = @staff_number or t_staff.id_card = @id_card)
begin
print ‘已存在’
return
end
else
commit tran
end
begin
update t_staff
set as_employee_type_id = @as_employee_type_id
, as_work_status_id = @as_work_status_id
,as_branch_id = @as_branch_id
, staff_name = @staff_name
,staff_number = @staff_number
,as_gender_id = @as_gender_id
,age = @age
,id_card = @id_card
,birth = @birth
,phone_number = @phone_number
,address = @address,e_mail = @e_mail
,entry_date = @entry_date
,departure_date = @entry_date
,operator_no = @operator_no
,picture = @picture,note = @note
where staff_id = @staff_id
end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值