-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5ad167
commit 3ff19b6
Showing
4 changed files
with
50 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
CREATE OR ALTER PROCEDURE QueryRooms | ||
@Room SMALLINT, | ||
@Floor SMALLINT, | ||
@Offset INT, | ||
@FetchNext INT | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON; | ||
|
||
WITH all_rooms (room, area, motorbike, car, residents) AS ( | ||
SELECT | ||
IIF(rooms.room IS NULL, approved_residents.room, rooms.room), | ||
area, | ||
motorbike, | ||
car, | ||
IIF(residents IS NULL, 0, residents) | ||
FROM rooms | ||
FULL OUTER JOIN ( | ||
SELECT room, COUNT(1) AS residents | ||
FROM accounts | ||
WHERE approved = 1 | ||
GROUP BY room | ||
) AS approved_residents ON rooms.room = approved_residents.room | ||
) | ||
SELECT * FROM all_rooms | ||
WHERE (@Room IS NULL OR @Room = room) AND (@Floor IS NULL OR @Floor = room / 100) | ||
ORDER BY room | ||
OFFSET @Offset ROWS | ||
FETCH NEXT @FetchNext ROWS ONLY | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters