support 86837 (12/18/2012)
I have two tables, one for Orders and then an Assiged Parcels table which can have multiple records attached to an Order. In the Order table is column Pieces, which must match the count for Assigned Parcels.Here is my code. What am I doing wrong?
It's an Order of Evaluation issue. You use the WHERE clause to filter what goes into the aggregation, then you use the HAVING clause to filter the results of the aggregation, like so:
SELECT
PA.OrderID,
COUNT(*) AS 'TotalParcels'
FROM
tblParcelAssigned as PA
INNER JOIN
tblOrder AS O
ONO.OrderID = PA.OrderID
WHERE
PA.Type = 2
HAVING
o.Pieces <> Count(*)
GROUP BY
PA.OrderID
ORDER BY
PA.OrderID
DESC
I also need to make the Orders table 'clickable' in the results.
I'm not entirely sure what you mean by this.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA