TRANSACT-SQL Tips

1. Get only date part for comparing.

FLOOR(CAST(GETDATE() AS FLOAT))

2. Paging

DECLARE @PageNum int
DECLARE @PageSize int
SET @PageNum = 2
SET @PageSize = 20;
WITH cte AS
(
    SELECT tbl.*, ROW_NUMBER() OVER(ORDER BY Article_Id) AS RowNum
    FROM SomeTable tbl
)
SELECT * FROM cte
WHERE RowNum BETWEEN (@PageNum-1) * @PageSize AND @PageNum * @PageSize;

posted @ 2009-07-28 22:39  sadcat  阅读(113)  评论(0编辑  收藏  举报