dbo.GetSiteAccoutDetail.StoredProcedure.sql
5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
USE [AIADatabaseV5]
GO
/****** Object: StoredProcedure [dbo].[GetSiteAccoutDetail] Script Date: 2/1/2018 12:15:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: magic
-- Create date: 14/4/2009
-- Description: Fetch building level accounts details for corresponding given Account Number.
-- =============================================
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetSiteAccoutDetail]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetSiteAccoutDetail]
GO
CREATE PROCEDURE [dbo].[GetSiteAccoutDetail]
-- Add the parameters for the stored procedure here
@strAccountNumber varchar(50)='', @pageNo int, @pageLength int, @recordCount int out
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--Get the records on the basis of parameters page length and page number rows
select LD.Id, LD.SiteIp, LD.Title, LD.SiteIPTo, LD.SiteMasterIPTo, LD.CreationDate, LD.ModifiedDate, LD.InstituteName,
LD.Department, LD.UserId, LD.FirstName, LD.EmailId
from
(Select ROW_NUMBER() OVER (ORDER BY Site.Id) AS RowNo,
Site.Id,Site.SiteIp,Site.Title,ISNULL(Site.SiteIPTo,'') as SiteIPTo,ISNULL(Site.SiteMasterIPTo,'') as SiteMasterIPTo,
CONVERT(VARCHAR,Site.CreationDate,101) as CreationDate,
CONVERT(VARCHAR,Site.ModifiedDate,101) as ModifiedDate,
Site.InstituteName,Site.Department, AIAUser.Id as UserId,AIAUser.FirstName,AIAUser.EmailId
From ((Site INNER JOIN AIAUserToSite on Site.Id=AIAUserToSite.SiteId)
INNER JOIN AIAUser on AIAUserToSite.UserId = AIAUser.Id)
Where Site.IsActive=1 and Site.id in
(Select SiteID From SiteToLicenseEdition Where LicenseEditionId in
(Select Id From LicenseToEdition Where LicenseId in
(Select Id From License Where LicenseTypeId=3 and AccountNumber=@strAccountNumber))))
as LD
where
RowNo > @pageLength * (@pageNo - 1) AND
RowNo <= @pageLength * @pageNo
--Calculate total number of records
select @recordCount = count(ResultTable.Id) from
(Select Site.Id,Site.SiteIp,Site.Title,ISNULL(Site.SiteIPTo,'') as SiteIPTo,ISNULL(Site.SiteMasterIPTo,'') as SiteMasterIPTo,
CONVERT(VARCHAR,Site.CreationDate,101) as CreationDate,
CONVERT(VARCHAR,Site.ModifiedDate,101) as ModifiedDate,
Site.InstituteName,Site.Department, AIAUser.Id as UserId,AIAUser.FirstName,AIAUser.EmailId
From ((Site INNER JOIN AIAUserToSite on Site.Id=AIAUserToSite.SiteId)
INNER JOIN AIAUser on AIAUserToSite.UserId = AIAUser.Id)
Where Site.IsActive=1 and Site.id in
(Select SiteID From SiteToLicenseEdition Where LicenseEditionId in
(Select Id From LicenseToEdition Where LicenseId in
(Select Id From License Where LicenseTypeId=3 and AccountNumber=@strAccountNumber)))) as ResultTable;
END
GO