1
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

1
  • 1
    "It is getting failed" - with an error or it doesn't do what you expect it to do? Can you add your exact query, including the update statement? If it generates an error, can you please post it as well? Commented Dec 6, 2010 at 13:16

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

The SELECT inside the conditional seems to be missing something. Try:

select Empid from Table1 where empname=@strempname and Empid=@Intempid and DEptid<>@intdepID

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.