﻿USE [AIADatabaseV5]
GO
/****** Object:  StoredProcedure [dbo].[GetLicenseIdBySiteUrl]    Script Date: 2/1/2018 12:15:55 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<magicsw>
-- Create date: <16/02/2010>
-- Description:	<Fetch all the module list>
-- =============================================

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

CREATE PROCEDURE [dbo].[GetLicenseIdBySiteUrl]
	-- Add the parameters for the stored procedure here
	@sLicenseAccount varchar(100), @iEditionId int
AS
BEGIN
	IF 1=0 BEGIN
		SET FMTONLY OFF
	END
	SELECT distinct Site.Id,
	ISNULL(SUBSTRING(REPLACE(REPLACE(REPLACE(Site.SiteIP+'/','www.',''),'http://',''),'https://',''),0,
		CHARINDEX('/',REPLACE(REPLACE(REPLACE(Site.SiteIP+'/','www.',''),'http://',''),'https://',''))),'') as SiteIp,
	ISNULL(SUBSTRING(REPLACE(REPLACE(REPLACE(Site.SiteIPTo+'/','www.',''),'http://',''),'https://',''),0,
		CHARINDEX('/',REPLACE(REPLACE(REPLACE(Site.SiteIPTo+'/','www.',''),'http://',''),'https://',''))),'') as SiteIPTo,
	ISNULL(SUBSTRING(REPLACE(REPLACE(REPLACE(Site.SiteMasterIPTo+'/','www.',''),'http://',''),'https://',''),0,
		CHARINDEX('/',REPLACE(REPLACE(REPLACE(Site.SiteMasterIPTo+'/','www.',''),'http://',''),'https://',''))),'') as SiteMasterIPTo,Site.IsMaster
	FROM License INNER JOIN LicenseToEdition ON License.Id = LicenseToEdition.LicenseId 
	INNER JOIN SiteToLicenseEdition ON LicenseToEdition.Id = SiteToLicenseEdition.LicenseEditionId 
	INNER JOIN Site ON SiteToLicenseEdition.SiteId = Site.Id WHERE 
	(License.AccountNumber = @sLicenseAccount) AND (LicenseToEdition.EditionId = @iEditionId)


END

GO
