日期:2014-05-17  浏览次数:20425 次

这句话为什么会报错?奇怪。
select * from (

(select * from (select distinct b.CustomNm,b.CIFNm,b.ApproveNm,b.loannm, b.LoanAmount,a.LoanBalance,b.LoanPerid,
b.LoanStratDate,b.LoanEndDate,b.ComyLoanPurpose from InterestReceive a right join OPSInf b on a.ContractNm=b.LoanNm) aa

join 
---连接客户类型
 (select distinct * from (select a.LoanAccount,a.LoanNm,case b.LoanType 
  when '个人客户' then b.PerType
  when '企业客户' then b.ComyCustomType 
  else '' end tp
from
OPSInf a left join LoanInf b on a.CIFNm=b.CIFNm) cc ) dd
on aa.LoanNm =dd.LoanNm) bc

) sda


------解决方案--------------------
最后那个) sda多出来了
SQL code
SELECT  *
 FROM    ( SELECT  *
             FROM    ( SELECT DISTINCT
                                 b.CustomNm ,
                                 b.CIFNm ,
                                 b.ApproveNm ,
                                 b.loannm ,
                                 b.LoanAmount ,
                                 a.LoanBalance ,
                                 b.LoanPerid ,
                                 b.LoanStratDate ,
                                 b.LoanEndDate ,
                                 b.ComyLoanPurpose
                       FROM      InterestReceive a
                                 RIGHT JOIN OPSInf b ON a.ContractNm = b.LoanNm
                     ) aa
                     JOIN ---连接客户类型
                     ( SELECT DISTINCT
                                 *
                       FROM      ( SELECT    a.LoanAccount ,
                                             a.LoanNm ,
                                             CASE b.LoanType
                                               WHEN '个人客户' THEN b.PerType
                                               WHEN '企业客户'
                                               THEN b.ComyCustomType
                                               ELSE ''
                                             END tp
                                   FROM      OPSInf a
                                             LEFT JOIN LoanInf b ON a.CIFNm = b.CIFNm
                                 ) cc
                     ) dd ON aa.LoanNm = dd.LoanNm
           ) bc

------解决方案--------------------
SQL code
--MSSQL的括号只能用来括住数据集 而不能用来括住一个表
--例如
select * from (ta )a  --报错
select * from (select * from ta)a --正确