我可以检查两个表中的值是否存在? [英] Ho do I check if value exsist in two tables ?
本文介绍了我可以检查两个表中的值是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有两张表,其中包含人员ID码及其类别代码。
Id,两个表的代码相同。
表格如下:
Hi all,
I have two tables with people id codes and their category code.
Id, codes are same for both tables.
Tables look like :
Table1
-----------
id|Code
1|10
2|25
3|21
4|10
5|10
Table2
------------
id|Code
1|902
2|903
3|904
4|926
推荐答案
SQL JOINS [ ^ ]。
hi
查看以下代码
--------------- ------------------------
创建视图viwename
as
选择id,来自table1的代码
union all
选择id,来自table2的代码
---------- ----------- ----------------------
创建程序dupchcking
(
@id int,@ code int
)
begin
if exists(选择id,来自viwename的代码,其中id = @id和code = @code)
开始
选择1
结束
其他
开始
选择0
结束
结束
hi check the fallowing code
---------------------------------------
create view viwename
as
select id,code from table1
union all
select id,code from table2
-------------------------------------------
create procedure duplicatechcking
(
@id int,@code int
)
begin
if exists(select id,code from viwename where id=@id and code=@code)
begin
select 1
end
else
begin
select 0
end
end
这篇关于我可以检查两个表中的值是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文