 @positiveOccurId int
AS 
BEGIN
	-- 0 for all screen, 1 screen having occur id > 0
	SET @positiveOccurId = COALESCE(@positiveOccurId, 0)
	--BMS Map
	 SELECT DISTINCT Bms.BmsName AS [screenName], Bms.occurid, Bms_1.BmsName AS [MAP SET], 119 AS screenType, Bms.BmsID
	 	FROM Bms  LEFT JOIN	Bms Bms_1 ON Bms.AncestorID = Bms_1.BmsID
	 	where (Bms_1.BmsName is not null) and (@positiveOccurId = 0 or Bms.occurid > 0)
	UNION 
	--ADS Map				
	 (SELECT DISTINCT AdsMaps.MapName AS [screenName], AdsMaps.occurid, null AS [MAP SET], 118 AS screenType, AdsMaps.MapID
		FROM AdsMaps
		where (@positiveOccurId = 0 or AdsMaps.occurid > 0))
	UNION 	
	--Natural Map
	 (SELECT DISTINCT NaturalMaps.MapName AS [screenName], NaturalMaps.OccurID, NaturalMaps_1.MapName AS [MAP SET], 120 AS screenType, NaturalMaps.MapID
		FROM NaturalMaps LEFT OUTER JOIN
	         NaturalMaps AS NaturalMaps_1 ON NaturalMaps.AncestorID = NaturalMaps_1.MapID
	         where NaturalMaps.MapID<>1 and (@positiveOccurId = 0 or NaturalMaps.OccurID > 0))
	UNION 
	--Smart/AS400
	 (SELECT DISTINCT ScreenDDS.ScreenName AS [screenName], ScreenDDS.OccurId, null AS [MAP SET], 121 AS screenType, ScreenDDS.ID 
	    FROM ScreenDDS where (@positiveOccurId = 0 or ScreenDDS.OccurId > 0))
	UNION 
	--TPMSX
	 (SELECT DISTINCT Resources.Name as screenName, null as OccurID, null as [MAP SET], 101 as screenType, Resources.ResourceID 
	From Resources where (Resources.ResourceType = 101 and @positiveOccurId = 0))
	UNION
	--IMS MAP
	 (SELECT DISTINCT IMSMaps.MapName as [screenName], IMSMaps.OccurID as OccurID, NULL as [MAP SET], 65 as screenType, IMSMaps.MapID 
	From IMSMaps
	where (IMSMaps.OccurID > 0 or @positiveOccurId = 0))
	ORDER BY screenName, screenType
END