开发者

sql Query Issue

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


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


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜