Reputation: 7777
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
Here i have 2 tables i am comparing two table values based on that i need to update the values int table 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
i am writing this Query, it is getting failed for that condition .
can any one help me out to write an Query for this
thanks
Upvotes: 1
Views: 58
Reputation: 219096
The SELECT
inside the conditional seems to be missing something. Try:
select Empid from Table1 where empname=@strempname and Empid=@Intempid and DEptid<>@intdepID
Upvotes: 0
Reputation: 17383
How about using such a query?
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
Upvotes: 2