Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:22:43+00:00 2026-06-11T13:22:43+00:00

I have created a stored procedure which works perfectly fine when I execute it

  • 0

I have created a stored procedure which works perfectly fine when I execute it from from end i.e.C#.net or when I copy and past the query of stored procedure in separate SQL Query window but it neither give any result nor any error when I execute it in SQL server using EXEC sp_Name. I can not understand what is wrong in my code.

Below is my stored procedure

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

I am executing it like this.

EXEC sp_tbl_REQUEST_SelectAllByFilter_WithPagging 1,20,NULL,NULL,74,591
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:22:45+00:00Added an answer on June 11, 2026 at 1:22 pm

    You’re passing NULL for @SortExpression and @SortDirection. NULL means that the defaults don’t apply – they’re null instead.

    So the whole concatenation into @SelectClause becomes NULL (because concatenating strings and NULLs produces NULLs)

    So nothing is executed.

    Try:

    EXEC sp_tbl_REQUEST_SelectAllByFilter_WithPagging
             1,20,@int_Requester_ID = 74,@intProjectID=591
    

    Incidentally, you should avoid using sp_ as a prefix for stored procedures. The sp_ prefix is reserved by MS for system stored procedures, and SQL Server will prefer a system stored procedure from master vs your own procedure, if there’s a name clash.

    (I’d generally recommend against using any prefixes in SQL Server, but that’s more of a matter for debate, rather than a strong rule)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just created a report in Report Manager using a Stored Procedure which
I have a stored procedure which returns a ref cursor as follows: CREATE OR
I have a stored procedure in which i want to create a user defined
I have a dynamic SQL statement I've created in a stored procedure. I need
I have a stored procedure which does sorting pnd Paging like the Sorting Custom
I have been able to execute a Stored Procedure in hibernate to map the
I have a simple question regarding T-SQL. I have a stored procedure which calls
I have stored procedure which update Customers and a datagridview to work with the
I have a stored procedure in Oracle 9i which inserts records in a table.
I have a Stored Procedure (SP) in which I pass in one value. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.