Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
SELECT

        LXA.AuctionID
        ,LAD.OpeningPrice
        ,AP.Description
        ,UR.Name
        ,UR.BigLeapID
        ,CONVERT(VARCHAR,LXA.Date)Date

     ,CASE WHEN LXA.IsAutoBid=1 then ISNULL(max(LXA.BidPrice),0)+LAD.BidIncrement else LXA.BidPrice End topay
  FROM  LiveXAuctionBid LXA
        INNER JOIN LiveAuctionBid LA ON LA.LiveAuctionBidID = LXA.LiveAuctionBidID
        INNER JOIN UserRegistration UR ON UR.UserRegistrationID = LA.UserID
        INNER JOIN LiveAuctionDetails LAD ON LAD.LiveAuctionDetailID = LXA.AuctionID
        INNER JOIN AuctionProduct AP ON AP.AuctionProductID = LAD.ProductID
  WHERE LAD.LiveAuctionDetailID = @LiveAuctionDetailID

  group by  LXA.AuctionID,LAD.OpeningPrice,AP.Description,UR.Name,UR.ID,Date



Error:

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

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

Column 'LiveXAuctionBid.BidPrice' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Posted
Comments
Thanks7872 7-Nov-14 3:43am    
And which part of the error is not clear to you?
Gokul Athithan 7-Nov-14 3:44am    
yes
/\jmot 7-Nov-14 3:52am    
Error occurring for this part..
CASE WHEN LXA.IsAutoBid=1 then ISNULL(max(LXA.BidPrice),0)+LAD.BidIncrement else LXA.BidPrice End topay
Gokul Athithan 7-Nov-14 3:56am    
how to clear the error
Tomas Takac 7-Nov-14 3:59am    
The CASE statement is your problem, it's a mess actually. Maybe you should start by trying to explain why do you need GROUP BY in the first place, then it becomes more clear.

When you use a GROUP BY clause, it aggregates records according to the specified groups: so if you group your customers by city, you get back "n" records, where "n" is the number of different cities your customers are based in. Within that query, you can't access individual customers except by using an aggregate function which (for example) counts them, or add them together - because the GROUP converts them to a single record.

I can't suggest what you need to do to fix you query - because I have no idea what your data looks like, or what result you expect to get - but you can't access the bid status, bid price or increment within the GROUP. Most likely, you need to use a sub query of some form instead of a group, but as I say, I can;t see your data.

Go back to the drawing board, and work out exactly what you are trying to return - build a "dummy data set" in Excel or on paper - and then look at how you extract that data. I think you are heading down the wrong road at the moment.
 
Share this answer
 
'having ' is used with group by function ....and also use aggregate function with fields except the group by fields like LXA.AuctionID,LAD.OpeningPrice,AP.Description,UR.Name,UR.ID,Date
 
Share this answer
 
Look ate this:
SQL
WITH cte AS (
SELECT 
    LXA.AuctionID
    , ISNULL(MAX(LXA.BidPrice), 0) AS MaxBidPrice
FROM LiveXAuctionBid LXA 
GROUP BY LXA.AuctionID
)
SELECT
    LXA.AuctionID
    ,LAD.OpeningPrice
    ,AP.Description
    ,UR.Name
    ,UR.BigLeapID
    ,CONVERT(VARCHAR,LXA.Date)Date
    ,CASE WHEN LXA.IsAutoBid=1 then cte.MaxBidPrice +LAD.BidIncrement else LXA.BidPrice End topay
FROM  LiveXAuctionBid LXA
INNER JOIN cte ON LXA.AuctionID = cte.AuctionID 
INNER JOIN LiveAuctionBid LA ON LA.LiveAuctionBidID = LXA.LiveAuctionBidID
INNER JOIN UserRegistration UR ON UR.UserRegistrationID = LA.UserID
INNER JOIN LiveAuctionDetails LAD ON LAD.LiveAuctionDetailID = LXA.AuctionID
INNER JOIN AuctionProduct AP ON AP.AuctionProductID = LAD.ProductID
WHERE LAD.LiveAuctionDetailID = @LiveAuctionDetailID
GROUP BY LXA.AuctionID,LAD.OpeningPrice,AP.Description,UR.Name,UR.ID,Date
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900