2012-08-31 49 views
1

asp.net SQL查詢錯誤我只是想通過顯示數據網格的細節使這個查詢在使用C#應用程序

select 
P.Sitename as Site 
,P.Vendorname as Vendor 
,P.POno,PS.Itemcode as ItemCode 
,sum(PS.Quantity) as Qty 
,sum(PS.Basic) as Basic 
,Sum(PS.DiscountAmt) as [Disc Amt] 
,sum(PS.PFAmt) as [PF Amt] 
,sum(PS.EDAmt) as [ED Amt] 
,sum(PS.VATCSTAmt) as [VATCST Amt] 
,sum(PS.Netamt) as Total 
,I.Itemname as Itemname 
,I.UOM as UOM 
from tbl_Itemmaster I, tbl_Purchaseorder_sub PS,tbl_Purchaseorder P 
where P.POdate between '8/30/2012' and '8/31/2012' 
and PS.status in (4,5) 
and I.Itemidentify=Ps.ITemcode 
and PS.pono=p.POno 
group by PS.Itemcode,P.Sitename,P.Vendorname,I.Itemname,I.UOM 
order by Site,Vendor,ItemCode 

的使用,但是,在執行這一點,這是我得到的錯誤,

"Column 'tbl_Purchaseorder.POno' is invalid in the select list because 
it is not contained in either an aggregate function or the GROUP BY clause." 

請誰能告訴我怎樣才能糾正

回答

1

您需要PONO添加到GROUP BY Cluase

喜歡的東西

select P.Sitename as Site, 
     P.Vendorname as Vendor, 
     P.POno, 
     PS.Itemcode as ItemCode, 
     sum(PS.Quantity) as Qty, 
     sum(PS.Basic) as Basic, 
     Sum(PS.DiscountAmt) as [Disc Amt], 
     sum(PS.PFAmt) as [PF Amt], 
     sum(PS.EDAmt) as [ED Amt], 
     sum(PS.VATCSTAmt) as [VATCST Amt], 
     sum(PS.Netamt) as Total , 
     I.Itemname as Itemname, 
     I.UOM as UOM 
from tbl_Itemmaster I, 
     tbl_Purchaseorder_sub PS, 
     tbl_Purchaseorder P 
where P.POdate between '8/30/2012' 
and  '8/31/2012' 
and  PS.status in (4,5) 
and  I.Itemidentify=Ps.ITemcode 
and  PS.pono=p.POno 
group by PS.Itemcode, 
      P.Sitename, 
      P.Vendorname, 
      I.Itemname, 
      I.UOM, 
      P.POno <-- You need to add this to your query 
order by Site, 
      Vendor, 
      ItemCode 
+0

感謝astander – user1632377

+0

請選擇這個作爲你的答案,如果它回答了你的問題 – Divi

+0

@ user1632377,有一種更好的方式來表示感謝。請參閱[接受答案如何工作?](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – Habib