 		EA.AccountID as AccountID
 	FROM @ItemsService AS I2
 	INNER JOIN ServiceItems AS SI2 ON I2.ItemID = SI2.ItemID
-	INNER JOIN ExchangeAccounts AS EA ON I2.ItemID = EA.ItemID
+	INNER JOIN ExchangeAccounts AS EA ON I2.ItemID = EA.ItemID'
+IF @FilterValue <> ''
+	SET @sqlSpace = @sqlSpace + ' WHERE (EA.DisplayName LIKE ''' + @FilterValue + ''')'
+SET @sqlSpace = @sqlSpace + '
 	UNION
-	SELECT
+	SELECT '
+
+IF @OnlyFind = 1
+SET @sqlSpace = @sqlSpace + 'TOP ' + CAST(@MaximumRows AS varchar(12)) + ' '
+
+SET @sqlSpace = @sqlSpace +	'
 		EA4.ItemID AS ItemID,
 		EA4.PrimaryEmailAddress as TextSearch,
 		''ExchangeAccount'' as ColumnType,

		ItemID int
	)
	INSERT INTO @ItemsService (ItemID)
	SELECT '

IF @OnlyFind = 1
SET @sqlSpace = @sqlSpace + 'TOP ' + CAST(@MaximumRows AS varchar(12)) + ' '

SET @sqlSpace = @sqlSpace +	'SI.ItemID
	FROM ServiceItems AS SI
	INNER JOIN Packages AS P ON P.PackageID = SI.PackageID
	INNER JOIN UsersDetailed AS U ON P.UserID = U.UserID

FROM dbo.Users AS U3) as U
WHERE TextSearch<>'' '' OR ISNULL(TextSearch, 0) > 0
)
 AS U ON TU.UserID = U.ItemID'
IF @FilterValue <> ''
	SET @sqlUsers = @sqlUsers + ' WHERE TextSearch LIKE ''' + @FilterValue + ''''
SET @sqlUsers = @sqlUsers + ' ORDER BY TextSearch'

SET @sqlUsers = @sqlUsers + ' open @curValue'

