当前位置: 代码迷 >> Sql Server >> 请教这句话有什么有关问题,如何改
  详细解决方案

请教这句话有什么有关问题,如何改

热度:72   发布时间:2016-04-27 20:39:20.0
请问这句话有什么问题,怎么改?
declare     @deptfullname   varchar(100)
select   a.deptid   ,   @deptfullname   =   d1.orgName+d2.orgName
  from   DeptInfo   a  
left   join   OrgInfo   d1   on   a.Org1   =   d1.OrgId   left   join   OrgInfo   d2   on   a.Org2   =   d2.OrgId  
where   a.DeptId=154

错误提示:A   SELECT   statement   that   assigns   a   value   to   a   variable   must   not   be   combined   with   data-retrieval   operations.

要达到这个效果该怎么改呢?谢谢了!

------解决方案--------------------
select a.deptid ,deptfullname = d1.orgName+d2.orgName
from DeptInfo a
left join OrgInfo d1 on a.Org1 = d1.OrgId
left join OrgInfo d2 on a.Org2 = d2.OrgId
where a.DeptId=154
------解决方案--------------------
declare @deptfullname varchar(100)
select @deptfullname = d1.orgName+d2.orgName
from DeptInfo a
left join OrgInfo d1 on a.Org1 = d1.OrgId left join OrgInfo d2 on a.Org2 = d2.OrgId
where a.DeptId=154
  相关解决方案