Хранимую процедуру SQL оператор SELECT
I have another field in my database table called FileName, I want the record to be selected by FileName. What should I add to the code
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spx_Pager]
@PageNo int = 1,
@ItemsPerPage int = 2,
@TotalRows int out,
@f_name nvarchar(50)
AS
BEGIN
SET NOCOUNT ON
DECLARE
@StartIdx int,
@SQL nvarchar(max),
@SQL_Conditions nvarchar(max),
@EndIdx int
IF @PageNo < 1 SET @PageNo = 1
IF @ItemsPerPage < 1 SET @ItemsPerPage = 10
SET @StartIdx = (@PageNo -1) * @ItemsPerPage + 1
SET @EndIdx = (@StartIdx + @ItemsPerPage) - 1
SET @f_name = (@f_name)
SET @SQL = 'SELECT FilePath
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Row, *
FROM tblFiles ) AS tbl WHERE Row >= '
+ CONVERT(varchar(9), @StartIdx) + ' AND
Row <= ' + CONVERT(varchar(9), @EndIdx)
EXEC sp_executesql @SQL
SET @SQL = 'SELECT @TotalRows=COUNT(*) FROM tblFiles'
EXEC sp_executesql
@query = @SQL,
@params = N'@TotalRows INT OUTPUT',
@TotalRows = @TotalRows OUTPUT
END
What I have tried:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spx_Pager]
@PageNo int = 1,
@ItemsPerPage int = 2,
@TotalRows int out,
@f_name nvarchar(50)
AS
BEGIN
SET NOCOUNT ON
DECLARE
@StartIdx int,
@SQL nvarchar(max),
@SQL_Conditions nvarchar(max),
@EndIdx int
IF @PageNo < 1 SET @PageNo = 1
IF @ItemsPerPage < 1 SET @ItemsPerPage = 10
SET @StartIdx = (@PageNo -1) * @ItemsPerPage + 1
SET @EndIdx = (@StartIdx + @ItemsPerPage) - 1
SET @f_name = (@f_name)
SET @SQL = 'SELECT FilePath
FROM (
SELECT ROW_NUMBER() OVER(ORDER BY ID) AS Row, *
FROM tblFiles ) AS tbl WHERE Row >= '
+ CONVERT(varchar(9), @StartIdx) + ' AND
Row <= ' + CONVERT(varchar(9), @EndIdx) + ' AND FileName = img1'
EXEC sp_executesql @SQL
SET @SQL = 'SELECT @TotalRows=COUNT(*) FROM tblFiles'
EXEC sp_executesql
@query = @SQL,
@params = N'@TotalRows INT OUTPUT',
@TotalRows = @TotalRows OUTPUT
END