SQL存储过程选择语句

时间:2016-08-12 10:56:24

标签: sql-server

我的数据库表中有另一个名为FileName的字段,我希望通过FileName选择记录。我应该在代码中添加什么。

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

1 个答案:

答案 0 :(得分:0)

你没有给我太多的信息。但这是你需要的吗?

while(true){
    if(in.hasNextLine()){
        processLine(in.nextLine());
        timeLastRecieved = System.currentTimeMillis();
    }

    //Check for a timout
    if(timeLastRecieved+timeoutDuration <= System.currentTimeMillis())
        timeUserOut();
}