Click here to Skip to main content
14,920,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i get error below when add GROUP BY dbo.TBLTicketAnswers.AnswerID

Msg 8120, Level 16, State 1, Procedure GetTicketBySearch, Line 21
Column 'dbo.TBLTickets.UserID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

SELECT  TBLTickets.UserID ,
                            TBLTickets.TicketID ,
                            TBLTickets.AttachFile ,
                            TBLTickets.HasFile ,
                            TBLTickets.Title ,
                            TBLTickets.Question ,
                            TBLTicketBranchs.BranchName ,
                            TBLTicketAnswers.AnswerID ,
                            TBLTicketAnswers.Answer ,
                            TBLTickets.Flag ,
                            TBLUsers.UserName ,
                            TBLTickets.InsertDate ,
                            TBLUsers.UserOwner ,
                    FROM    dbo.TBLTicketBranchs
                            INNER JOIN dbo.TBLTickets ON dbo.TBLTicketBranchs.BranchID = dbo.TBLTickets.BranchID
                            INNER JOIN dbo.TBLUsers ON dbo.TBLTickets.UserID = dbo.TBLUsers.UserID
                            LEFT OUTER JOIN dbo.TBLTicketAnswers ON dbo.TBLTickets.TicketID = dbo.TBLTicketAnswers.TicketID
                    WHERE   ( TBLTicketBranchs.ResellerID = @ResellerID   
                              AND ( TBLTicketAnswers.Answer LIKE N'%'
                                    + @Keyword + '%'
                                    OR @Keyword IS NULL
                                    OR TBLTickets.Title LIKE N'%' + @Keyword
                                    + '%'
                                    OR @Keyword IS NULL
                                    OR TBLTickets.Question LIKE N'%'
                                    + @Keyword + '%'
                                    OR @Keyword IS NULL
                                    OR TBLUsers.UserName LIKE N'%' + @Keyword
                                    + '%'
                                    OR @Keyword IS NULL
          GROUP BY dbo.TBLTicketAnswers.AnswerID

1 solution

You can't use GROUP BY[^] without one of aggregate functions[^].

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