当前位置: 代码迷 >> ASP.NET >> 怎么把这两条SQL语句写成一条语句
  详细解决方案

怎么把这两条SQL语句写成一条语句

热度:5766   发布时间:2013-02-25 00:00:00.0
如何把这两条SQL语句写成一条语句。
两个表中通过iDCID关联
首先通过一次查询得到A表的iDCID值,然后用这个之去查B表。

步骤是:1〉select iDCID from KHGL_Customer where iCustomerId=@iCustomerId 
   
 2〉select iDCID,cDCName from basic_DistrictClass where basic_DistrictClass.iDCID=KHGL_Customer.iDCID 


------解决方案--------------------------------------------------------
select iDCID,cDCName from basic_DistrictClass where basic_DistrictClass.iDCID in ( select iDCID from KHGL_Customer where iCustomerId=@iCustomerId )
------解决方案--------------------------------------------------------
SQL code
select iDCID,cDCName from basic_DistrictClass where basic_DistrictClass.iDCID in ( select iDCID from KHGL_Customer where  iCustomerId=@iCustomerId )
------解决方案--------------------------------------------------------
C# code
select iDCID,cDCName from basic_DistrictClass where basic_DistrictClass.iDCID in ( select iDCID from KHGL_Customer where  iCustomerId=@iCustomerId )
------解决方案--------------------------------------------------------
select k.iDCID,b.cDCName from KHGL_Customer as k join basic_DistrictClass b on k.iDCID=b.iDCID where iCustomerId=@iCustomerId
  相关解决方案