2010-02-19 44 views
2

下面是一個查詢只有一個表達式可以在選擇列表中指定當子查詢未與EXISTS引入

select IssueNo, KendraCode, IssueTime, DateOfIssue, P_MotaBags, P_MotaWeight, P_PatlaBags, P_PatlaWeight, P_SarnaBags, P_SarnaWeight, NewBags,OldBags, TransporterName, TruckNumber, DriverName, TruckOwner,SocietyCode 
, 
(SELECT PaddyMotaW, PaddyPatlaW, PaddySarnaW, BagsMota, BagsPatla, BagsSarna,PC_ID, sangrahankendraid, SocietyCode,DM_ID FROM ReceiveFromSociety WHERE DM_ID=S.IssueNo) 
from IssueToSangrahanKendra_Soc S 
where KendraCode='4403' order by SocietyCode 

問題出在哪裏

回答

5

你不能在那樣的子查詢中選擇多個字段,只有1個字段將被允許。

另外,對代碼進行格式化將使得將來更容易閱讀。

請嘗試以下

select IssueNo, 
     KendraCode, 
     IssueTime, 
     DateOfIssue, 
     P_MotaBags, 
     P_MotaWeight, 
     P_PatlaBags, 
     P_PatlaWeight, 
     P_SarnaBags, 
     P_SarnaWeight, 
     NewBags, 
     OldBags, 
     TransporterName, 
     TruckNumber, 
     DriverName, 
     TruckOwner, 
     SocietyCode, 
     rfs.* 
from IssueToSangrahanKendra_Soc S LEFT JOIN 
     ( SELECT PaddyMotaW, 
        PaddyPatlaW, 
        PaddySarnaW, 
        BagsMota, 
        BagsPatla, 
        BagsSarna, 
        PC_ID, 
        sangrahankendraid, 
        SocietyCode, 
        DM_ID 
      FROM ReceiveFromSociety 
     ) rfs ON rfs.DM_ID =S.IssueNo 
where KendraCode='4403' 
order by SocietyCode 
+0

感謝和抱歉,沒有格式化代碼:) – 2010-02-19 09:08:33

相關問題