SQL Server 2008 R2分页日期参数不返回结果

时间:2015-02-16 10:26:27

标签: sql sql-server-2008-r2

任何人都可以看到我在这个SQL代码中出错了,因为它没有返回任何记录

SELECT *
       FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY [ContextId]) AS RowNum
          FROM [dbo].[tblWorkFlow] ) AS WFC
       WHERE WFC.ContextId = @ContextId 
         And WFC.Date = '2014-01-30' 
         And (WFC.RowNum between (
          (@PageNumber-1)*@RecordsPerPage)+1 AND @RecordsPerPage*(@PageNumber)
         )

它应该返回1条记录,因为这个sql显示

SELECT  @TotalRecords = (
  Select Count(TblColumnId) 
  FROM [dbo].[tblWorkFlow] 
  WHERE ContextId = @ContextId 
    AND date = @LastModified
) 

我无法弄清楚我做错了什么

1 个答案:

答案 0 :(得分:0)

尝试这种方式

转换(日期,WFC.Date)=转换(日期,'2014-01-30')

查询设置如下

      SELECT * FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY [ContextId]) AS RowNum
      FROM [dbo].[tblWorkFlow] ) AS WFC
      WHERE WFC.ContextId = @ContextId and Convert(date,WFC.Date) =  Convert(date,'2014-01-30')
      and (WFC.RowNum between ((@PageNumber-1)*@RecordsPerPage)+1 AND @RecordsPerPage*(@PageNumber))