1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-29 13:25:17 +01:00
bitwarden-server/util/Migrator/DbScripts/2024-06-27_00_AddOccupiedSeatsToProviderOrganizationOrganizationDetailsView.sql
Alex Morask 07d37b1b41
[AC-2805] Add AssignedSeats to ProviderOrganizationOrganizationDetailsView (#4446)
* Add 'AssignedSeats' to ProviderOrganizationOrganizationDetailsView

* Add newline

* Thomas' feedback
2024-07-03 10:33:37 -04:00

23 lines
700 B
Transact-SQL

-- Add column 'AssignedSeats'
CREATE OR AlTER VIEW [dbo].[ProviderOrganizationOrganizationDetailsView]
AS
SELECT
PO.[Id],
PO.[ProviderId],
PO.[OrganizationId],
O.[Name] OrganizationName,
PO.[Key],
PO.[Settings],
PO.[CreationDate],
PO.[RevisionDate],
(SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status = 2) UserCount,
(SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status >= 0) OccupiedSeats,
O.[Seats],
O.[Plan],
O.[Status]
FROM
[dbo].[ProviderOrganization] PO
LEFT JOIN
[dbo].[Organization] O ON O.[Id] = PO.[OrganizationId]
GO