In the below query I have a table name indent I have different indentid count for different locations. But it shows the indentid count for last location. I want to display all location indentID count.
I want to display count like this
15
20
1
- 15 - for first location
- 20 - second location
- 1 - third Location
Code:
DECLARE @LocationID int
SELECT @LocationID = LocationID FROM Locations
SELECT COUNT(IndentID) AS OpenedIndent
FROM Indent I
WHERE POStatusID IN (1,2)
AND I.LocationID = @LocationID
SELECT @LocationID = LocationID FROM Locationswithout awherecondition because it is not limiting the results to 1 record (you can only assign 1 value to a scalar variable).