1

您好我想执行这两个查询并在列表视图中同时显示结果。如何在一个选择命令中执行此查询:

我的 sql 查询:

Shareholder details:
   Select inlt_parentcompanyid,inlt_effectinterest,inlt_sharetype,inlt_shares from InterestLogTable where inlt_childcompid=5
    Subsidiary details:
    select inlt_childcompid,inlt_effectinterest,inlt_sharetype,inlt_shares from InterestLogTable where inlt_parentcompanyid =5

我的 asp.net 列表视图:

Shareholder details:
                    <td><%#Eval("owner_parentCompanyId")%>&nbsp;</td> 
                    <td><%#Eval("owner_sharetype")%>&nbsp;</td>
                    <td><%#Eval("owner_effectinterest")%>&nbsp;</td>   
                    <td><%#Eval("owner_deemedinterest")%>&nbsp;</td>                 
                    <td><%#Eval("owner_shares")%>&nbsp;</td> 

Sunsidiary details:
                    <td><%#Eval("owner_childCompanyId")%>&nbsp;</td> 
                    <td><%#Eval("owner_sharetype")%>&nbsp;</td>
                    <td><%#Eval("owner_effectinterest")%>&nbsp;</td>   
                    <td><%#Eval("owner_deemedinterest")%>&nbsp;</td>                 
                    <td><%#Eval("owner_shares")%>&nbsp;</td> 
4

1 回答 1

0

要在同一个列表视图中使用它,您的查询应该返回一个包含两个表中的列的单一结果集。为此,您必须进行内部连接。像这样

 Select inlt_parentcompanyid,inlt_effectinterest,inlt_sharetype,inlt_shares,inlt_childcompid,inlt_effectinterest,inlt_sharetype,inlt_shares from InterestLogTable INNER JOIN InterestLogTable ON InterestLogTable.intl_parentcompanyid=InterestLogTable.inlt_parentcompanyid where 

InterestLogTable.intl_parentcompanyid=5

当然,您需要使用 tableName.coulumnName 来处理两个表中相同的列名

于 2012-05-24T09:20:09.253 回答