Sorry Tara,here is the entire Sp:ALTER PROCEDURE [dbo].[USP_GetOBProjectsByModuleCount] @UserName nvarchar(50), @ProgID INT, @ModuleType nvarchar(50), @gLanguage nvarchar(20), @searchKey varchar(50) ASDECLARE @ErrorCode intDECLARE @EnterpriseLevelAccess INT --- changed from Varchar(50)DECLARE @UserID as intdeclare @query nvarchar(2000)SET NOCOUNT ONSELECT @ErrorCode = @@ErrorIF @ErrorCode = 0BEGIN SET @EnterpriseLevelAccess = (SELECT EnterpriseLevelAccess FROM TAB_Users WHERE UserName = @UserName) IF @EnterpriseLevelAccess = 1 OR @EnterpriseLevelAccess = 2 OR @EnterpriseLevelAccess = 3 BEGIN SET @UserID = (SELECT top 1 UserID FROM TAB_Users WHERE UserName = @UserName) set @query= N'select count(*) from (select ROW_NUMBER() OVER(ORDER BY projid) RowNr, * from (Select 0 as ProjID, ''* Select *'' as ProjNO,null as ProjName, null as AccessMode union SELECT projid, ProjNo, ProjName, 2 as AccessMode FROM TAB_Projects where ProgID = @ProgID AND Deleted = ''0'' and projno like ''%'+@searchKey+'%'' )t1 ) tab ' exec sp_executesql @query,N'@ProgID int',@ProgID SELECT @ErrorCode = @@Error END ELSE BEGIN IF @EnterpriseLevelAccess = 4 BEGIN /*Select 0 as ProjID, '* Select *' as ProjNO,null as ProjName, null as AccessMode union SELECT A.ProjID, B.ProjNO, B.ProjName, A.AccessMode FROM TAB_UserProjects AS A JOIN 'TAB_Projects AS B ON A.ProjID = B.ProjID WHERE A.UserID = @UserID AND A.AccessMode = 2 AND A.ProgID = @ProgID AND A.Deleted = '0' AND B.Deleted = 0 */ set @query= N'select count(*) from (select ROW_NUMBER() OVER(ORDER BY projid) RowNr, * from (Select 0 as ProjID, ''* Select *'' as ProjID,null as ProjName, null as AccessMode union SELECT A.projid, B.ProjNo, B.ProjName, A.AccessMode FROM TAB_Projects AS A JOIN TAB_Projects AS B ON A.ProjID = B.ProjID WHERE A.UserID = @UserID AND A.AccessMode = 2 AND A.ProgID = @ProgID AND A.Deleted = ''0'' AND B.Deleted = 0 and projno like ''%'+@searchKey+'%'' )t1 ) tab order by projno asc ' exec sp_executesql @query,N'@ProgID int',@ProgID SELECT @ErrorCode = @@Error END ELSE BEGIN IF @EnterpriseLevelAccess = 5 BEGIN /*Select 0 as ProjID, '* Select *' as ProjNO,null as ProjName, null as AccessMode union SELECT Distinct A.ProjID, B.ProjNO, B.ProjName, A.AccessMode FROM TAB_UserContracts AS A JOIN TAB_Projects AS B ON A.ProjID = B.ProjID WHERE A.UserID = @UserID AND A.AccessMode = 2 AND A.ProgID = @ProgID AND A.Deleted = '0' AND B.Deleted = 0 */ set @query= N'select count(*) from (select ROW_NUMBER() OVER(ORDER BY projid) RowNr, * from (Select 0 as ProjID, ''* Select *'' as ProjID,null as ProjName, null as AccessMode union SELECT A.projid, B.ProjNo, B.ProjName, A.AccessMode FROM TAB_Projects AS A JOIN TAB_Projects AS B ON A.ProjID = B.ProjID WHERE A.UserID = @UserID AND A.AccessMode = 2 AND A.ProgID = @ProgID AND A.Deleted = ''0'' AND B.Deleted = 0 and projno like ''%'+@searchKey+'%'' )t1 ) tab order by projno asc ' exec sp_executesql @query,N'@ProgID int',@ProgID set @ErrorCode = @@Error END END ENDENDSET NOCOUNT OFFRETURN @ErrorCode