Invalid object name 'column_name' I have created a procedure as

create procedure testPagination
(
@PageNumber bigint,
@PageSize Bigint,
@OrderByColumn varchar(1000),
@OrderType varchar(1000)
)
As
Begin
    --print @PageNumber
    --print @PageSize

    declare @strSQL nvarchar(max)
    declare @intStartSrNo bigint
    declare @intEndSrNo bigint

    if @OrderType = 'asc' 
    begin
        set @intStartSrNo=((@PageNumber*@PageSize)-@PageSize)
        set @intEndSrNo=(@PageNumber*@PageSize)
    end
    else if @OrderType = 'desc' 
    begin
        create table #RecCount(cnt bigint)
        declare @intTotRecords bigint
        set @strSQL='insert into #RecCount(cnt) select isnull(max(a.sr_no),0) from ' + @OrderByColumn + ' a with(nolock)'
        exec sp_executesql @strSQL
        select @intTotRecords=cnt from #RecCount



        set @intStartSrNo=(@intTotRecords-(@PageNumber*@PageSize))+1
        set @intEndSrNo=((@intStartSrNo-1)+@PageSize)

    end
    else
    begin
        return
    end


    if @OrderType = 'asc' 
    begin
        set @strSQL=
        '
        select a.sr_no, bv.id,bv.name_voter,bv.home_street_address_1, bv.home_address_city from ' + @OrderByColumn + ' a with(nolock) ' +
        ' inner join base_voter bv with(nolock) on bv.id=a.base_voter_id where a.sr_no &gt; ' + cast(@intStartSrNo as varchar(500)) + ' and a.sr_no &lt;= ' + cast(@intEndSrNo as varchar(500))
    end
    else if @OrderType = 'desc' 
    begin
        set @strSQL=
        '
        select a.sr_no, bv.id,bv.name_voter,bv.home_street_address_1, bv.home_address_city from ' + @OrderByColumn + ' a with(nolock) ' +
        ' inner join base_voter bv with(nolock) on bv.id=a.base_voter_id where a.sr_no &gt;= ' + cast(@intStartSrNo as varchar(500)) + ' and a.sr_no &lt;= ' + cast(@intEndSrNo as varchar(500))
    end
    --print @strSQL
    exec sp_executesql @strSQL
    return

End
go


3 indexes as

 create index IX_base_voter_name_voter_asc_deleted_at on base_voter(name_voter asc,deleted_at) include(home_street_address_1, home_address_city) where deleted_at is null 
 create index IX_base_voter_home_street_address_1_asc_deleted_at on base_voter(home_street_address_1 asc,deleted_at) include(name_voter, home_address_city) where deleted_at is null 
 create index IX_base_voter_home_address_city_asc_deleted_at on base_voter(home_address_city asc,deleted_at) include(name_voter, home_street_address_1) where deleted_at is null 


Now, when I try to execute this stored procedure I receive the error

Invalid Object name 'home_address_city'

I am executing by right-clicking on the stored procedure, which actually executes the following query

USE [test_db]
GO

DECLARE @return_value int

EXEC    @return_value = [dbo].[testPagination]
        @PageNumber = 1,
        @PageSize = 50,
        @OrderByColumn = N'home_address_city',
        @OrderType = N'asc'

SELECT  'Return Value' = @return_value

GO


I have already hit ctrl+shift+r a lot but with no success
Your proc contains this dynamic code:

set @strSQL='insert into #RecCount(cnt) select isnull(max(a.sr_no),0) from ' + @OrderByColumn + ' a with(nolock)'


When executed, this code throws the error mentioned above because from context it seems that Some Column is passed through @OrderByColumn, but your code tries to do a SELECT from this Some Column.