 		dbo.CheckUserParent(@UserID, P.UserID) = 1
 		
 	SET @curValue = cursor local for
-	SELECT
-		
+	SELECT '
+
+IF @OnlyFind = 1
+SET @sqlSpace = @sqlSpace + 'TOP ' + CAST(@MaximumRows AS varchar(12)) + ' '
+
+SET @sqlSpace = @sqlSpace +	'
 		SI.ItemID as ItemID,
 		SI.ItemName as TextSearch,
 		STYPE.DisplayName as ColumnType,

	UserID int
)
INSERT INTO @Users (UserID)
SELECT '

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

SET @sqlUsers = @sqlUsers + 'U.UserID
FROM UsersDetailed AS U
WHERE 
	U.UserID <> @UserID AND U.IsPeer = 0 AND

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'

