Table 1
Empaname empid Deptid
kumar 23 1
kumar 23 2
manu 45 3
manju 34 4
manju 34 5
manju 34 6
Table2
Empaname empid Deptid
kumar 23 1
manu 45 3
manju 34 5
这里我有2个表我比较两个表值基于我需要更新值int表2
if exists(select Empid from empname=@strempname and Empid=@Intempid and DEptid<>@intdepID)
Begin
//here both Empname and Empid is matching and DeptID is not matching then do not do anything just return an value as 2
return 2
end
else
begin
//Update the record vales to an Temp Table
end
我正在写这个查询,但是因为那个条件而失败了。
任何人都可以帮我写一个查询
谢谢
答案 0 :(得分:2)
使用这样的查询怎么样?
UPDATE ... -- T1 or T2
SET ... -- appropriate columns and values
FROM Table1 T1
INNER JOIN Table2 T2 ON T1.Empaname = T2.Empaname
AND T1.empid = T2.empid
AND T1.Deptid != T2.Deptid
答案 1 :(得分:0)
条件中的SELECT
似乎缺少某些东西。尝试:
select Empid from Table1 where empname=@strempname and Empid=@Intempid and DEptid<>@intdepID