2015-02-23 19 views
0

解決錯誤在存儲過程:不能申請內部加盟

  • 替換:vs.VehicleStatus VehicleStatus
  • 有了:max(vs.VehicleStatus) VehicleStatus

我在這個新領域的善意所闡述的問題有所幫助。

錯誤:因爲它不是在聚合函數或GROUP BY子句中包含

過程sp_VRMS_VehicleRequest_getvehiclerequestsgrouped,第25行
列「VRMS_VehicleStatus.VehicleStatus」在選擇列表中無效。

存儲過程的查詢:

SELECT max([VehicleRequestID]) VehicleRequestID 
     ,[AdminId] 
     ,max([DesireCarTypeId]) DesireCarTypeId 
     ,max([AssignCarTypeId]) AssignCarTypeId 
     ,max([Source]) Source 
     ,max([Destination]) Destination 
     ,max([Landmark]) Landmark 
     ,max([NumberOfPassenger]) NumberOfPassenger 
     ,CASE WHEN max([PickUpTIme])= min([PickUpTIme]) THEN null ELSE max([PickUpTIme]) END PickUpTill 
     ,min([PickUpTIme]) PickUpTIme 
     ,[BookingDate] 
     ,max([CarNumber]) CarNumber 
     ,max([DriverName]) DriverName 
     ,max([DriverMobile]) DriverMobile 
     ,max([AllocationDate]) AllocationDate 
     ,vs.VehicleStatus VehicleStatus 
     ,max([Remarks]) Remarks 
     ,max([CRFTRF]) CRFTRF 
     ,max([CostCentreNo]) CostCentreNo 
     ,max([DutyDetails]) DutyDetails 
    FROM 
     [dbo].[VRMS_VehicleRequest] As vr 
    INNER JOIN 
     VRMS_VehicleStatus as vs on vr.VehicleStatusID = vs.VehicleStatusID 
    GROUP BY 
    AdminId, Bookingdate 

回答

0

你應該子句中組添加vs.VehicleStatus,像這樣:

group by AdminId,Bookingdate,vs.VehicleStatus 
0

「非分組的列的聚合函數的要求是不是有些一般的SQL或SQL Server實現的任意語法限制!「它是簡單的邏輯,像被零除 - 它必須處理並明確處理,是否我們正在編寫SQL或工作出來的手工紙...

以上是this摘錄文章。閱讀它,它會回答你的問題。

0

請注意,當您應用GroupBy子句時,請確保select語句中的所有列應該是聚合函數,即max,Min,Count,Sum,Avg等,否則它們應該在您的組中條款。因此,您應該在group by子句中添加vs.VehicleStatus列,即Group By AdminId,BookingDate,vs.VehicleStatus。我希望這有幫助。