我创建了一个存储过程,当我从 ieC#.net 端执行它时,或者当我在单独的 SQL 查询窗口中复制并过去存储过程的查询时,它工作得非常好,但是当我执行它时它既没有给出任何结果也没有任何错误在 SQL Server 中使用 EXEC sp_Name。我无法理解我的代码有什么问题。
下面是我的存储过程
ALTER PROCEDURE sp_tbl_REQUEST_SelectAllByFilter_WithPagging
@PageIndex INT=NULL,
@PageRecord INT=NULL,
@SortExpression NVARCHAR (200)='int_Request_ID',
@SortDirection NVARCHAR (10)='ASC',
@int_Requester_ID INT=NULL,
@intProjectID INT=NULL
AS
BEGIN
SET NOCOUNT ON
DECLARE @StartRowIndex INT
SET @StartRowIndex=((@PageIndex-1)*@PageRecord)+1;
DECLARE @WhrClause VARCHAR(MAX)
SET @WhrClause= 'WHERE tr.int_Requester_ID = '+CONVERT(VARCHAR(MAX), @int_Requester_ID)
IF(@intProjectID>0)
BEGIN
SET @WhrClause=@WhrClause+' AND tr.int_Project_ID='+CONVERT(VARCHAR(MAX),@intProjectID)
END
DECLARE @SelectClause VARCHAR(MAX)
SET @SelectClause=';With AllRecords AS(SELECT Row_Number() OVER(ORDER BY '+CONVERT (VARCHAR (MAX), @SortExpression)+' '+CONVERT (VARCHAR (MAX), @SortDirection)+')AS ''RowNumber'',* FROM(SELECT tr.[int_Request_ID],
tr.[int_User_ID],
tr.[int_Project_ID],
tr.[str_Request_Type],
tr.[int_Account_ID],
tr.[int_Requester_ID],
tr.[int_User_Head_ID],
tr.[dt_Request_Date],
tr.[bln_IsApproved],
tr.[dt_Approval_Date],
tr.[str_Reject_Reason],
tr.[int_USER_ROLE],
tr.[int_AllocationType_ID],
tr.[int_NoofHourInMinute],
xyz.dbo.GetHourByMin(ISNULL(int_NoofHourInMinute,0)) as ''str_NoofHour'',
tr.[dt_StartDateToWork],
tr.[dt_EndDateToWork],
tr.[isAllowToAddTask],
tr.[isAllowToDeleteTask],
tr.[isAllowToAddCR],
tp.str_Project_Name,
tu.str_FullName AS str_User_Name,
tu1.str_FullName AS UserHeader,
tbl_Project_AllocationType.str_AllocationType,
tu2.str_FullName AS UserRequester,
tu2.str_EMAIL_ADDRESS as RequesterEmail
FROM [tbl_Requests] tr
INNER JOIN tbl_PROJECT tp ON tp.int_Project_ID = tr.int_Project_ID
INNER JOIN tbl_USER tu ON tu.int_USER_ID=tr.int_User_ID
LEFT JOIN tbl_USER tu1 ON tu1.int_USER_ID=tr.int_User_Head_ID
INNER JOIN tbl_USER tu2 ON tu2.int_USER_ID=tr.int_Requester_ID
inner join tbl_Project_AllocationType on tbl_Project_AllocationType.int_AllocationType_ID=tr.int_AllocationType_ID '+@WhrClause+'
)As Tmp)
SELECT * FROM
AllRecords WHERE RowNumber BETWEEN ' + CONVERT(VARCHAR(MAX), @StartRowIndex) + ' AND ' + CONVERT(VARCHAR(MAX), (@StartRowIndex + @PageRecord - 1)) + '
SELECT COUNT(TempTbl.int_Request_ID)As ''ReturnRecords'','+CONVERT(VARCHAR(MAX),@PageIndex)+'''PageIndex''
FROM (SELECT tr.[int_Request_ID]
FROM [tbl_Requests] tr '+@WhrClause+')as TempTbl;'
PRINT(@SelectClause)
DECLARE @SQL NVARCHAR(MAX)
SET @SQL=CONVERT(NVARCHAR(MAX),@SelectClause)
EXEC sp_executesql @SQL
END
我正在这样执行它。
EXEC sp_tbl_REQUEST_SelectAllByFilter_WithPagging 1,20,NULL,NULL,74,591