What is wrong with this code? What would be the correct syntax?
SELECT EmployeeID, SUM('More than 2 orders')
FROM Orders
WHERE EmployeeID >2
GROUP BY EmployeeID
Msg 8117, Level 16, State 1, Line 1
Operand data type varchar is invalid for sum operator.
SUM('More than 2 orders')is the part that doesn’t make sense, as the error message is trying to tell you — youSUMa number field (or expression), not a varchar (i.e. string) constant.What exactly are you trying to do here, with that “sum of a string”?
Edit: the OP clarifies in a comment (OP, editing your question is a better idea!):
To show which employees “have handled at least two orders”, assuming for example there’s a record in the table for each order that has been handled:
this doesn’t show exactly which orders those employees handled (the above clarification does not request it) nor does it show the number of such employees — if that’s what is required instead of the employees’ IDs,
If neither of these guesses (or my guess at the Orders table) is exactly what you want, please show that table’s schema (ideally just the parts that are relevant to the question) and a simple example of what output you want for a short sample content of the table — and please realize that reading your mind (when you don’t give the details of your problem) is not a worthwhile exercise on our part, so supplying all the relevant information, including your specs and ideally a small example, is by far the best way to get your questions answered rapidly and informatively.