USE [AIADatabaseV5]
GO
/****** Object:  StoredProcedure [dbo].[usp_GetSiteAccountAdmin]    Script Date: 2/1/2018 12:15:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		magic
-- Create date: 5/6/2018
-- Description:	Fetch building level accounts client admins for corresponding given Account Number.
-- =============================================

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_GetSiteAccountAdmin]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_GetSiteAccountAdmin]
GO

CREATE PROCEDURE [dbo].[usp_GetSiteAccountAdmin] 
	-- Add the parameters for the stored procedure here
	@AccountNumber varchar(50)=''
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT AIAUser.Id, AIAUser.Password, AIAUser.LoginId, AIAUser.FirstName, AIAUser.UserTypeId, AIAUser.LastName, AIAUser.EmailId, AIAUser.IsActive, 
           AIAUser.SecurityQuestionId, AIAUser.SecurityAnswer, AIAUser.CreatorId, AIAUser.CreationDate, AIAUser.ModifierId, AIAUser.ModifiedDate, 
           AIAUser.DeactivationDate
	FROM AIAUser 
		INNER JOIN AIAUserToLicenseEdition ON AIAUser.Id = AIAUserToLicenseEdition.UserId 
		INNER JOIN LicenseToEdition ON AIAUserToLicenseEdition.LicenseEditionId = LicenseToEdition.Id 
		INNER JOIN License ON LicenseToEdition.LicenseId = License.Id
		WHERE (AIAUser.IsActive = 1) AND (License.AccountNumber = @AccountNumber) AND (AIAUser.UserTypeId = 4);

END



GO
