下面是一个普通的查询,
其中包括了关键字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