本文介绍了storedprocedure用于根据条件查看表内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个名为T1& T2的表,这些表有一些记录
I have 2 tables named as T1 &T2 and these have some records
T1
-----
empno empname
--------- ------------
1 X
2 y
T2
-----
empno empname
--------- ------------
1 z
2 X
这些是记录,现在我想检查T1.empname = T2.empname如果它是真的我想要从T2中删除该记录,否则显示来自T2的所有值
THESE ARE THE RECORDS, NOW I WANT TO CHECK T1.empname=T2.empname if it true i want to delete that record from T2 else display all values from T2
推荐答案
if exists(select 1 from table1 a inner join table2 b on b.S_no=a.sl_no)
delete a from table1 a inner join table2 b on b.S_no=a.sl_no
else
select * from table2
create procedure DeleteEntry
as
delete a from products1 a
inner join products b on a.productname=b.productname
go
试试这个我测试过的。
2. (已添加来自另一个答案框)
try this i have tested.
2. (Added from another answer box)
alter procedure DeleteEntry
as
begin
delete a from products1 a
inner join products b on a.productname=b.productname
end
select * from products1
go
现在尝试这个..
[/编辑]
这篇关于storedprocedure用于根据条件查看表内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!