一個分頁的問題,DTCms3.0中,分頁是根據時間分頁的,若是當添加時間(add_time)都是同一個數值時,無論點擊第幾頁,顯示的數據都是同一個的內容,因而就有了須要把同一個時間改指定隨機日期的功能。dom
原貼腳本轉至http://bbs.csdn.net/topics/340165720 第7樓的feilniu同窗.spa
SQL腳本以下: .net
DECLARE
@BDate
datetime,
@EDate
datetime
SET
@BDate
=
'
20150701
'
--
下限
SET
@EDate
=
'
20150714 23:59:59
'
--
上限
SELECT id, random_datetime
=
DATEADD(second,
ABS(CHECKSUM(
NEWID()))
%
DATEDIFF(second,
@BDate,
@Edate),
@BDate)
FROM dbo.dt_article
WHERE id
BETWEEN
1
AND
100
生成的內容爲:code
id
random_datetime
3
2015-07-05 07:55:10.000
4
2015-07-08 06:15:06.000
9
2015-07-12 19:14:24.000
10
2015-07-11 20:13:05.000
12
2015-07-06 19:09:12.000
13
2015-07-09 10:28:59.000
14
2015-07-03 07:18:42.000
15
2015-07-06 09:46:29.000
此時的ID是對應dt_article表中的ID。blog
而後咱們能夠先把生成的數據寫到臨時表中,而後關聯更新!get
咱們修改腳本以下:it
SELECT id, random_datetime
=
DATEADD(second,
ABS(CHECKSUM(
NEWID()))
%
DATEDIFF(second,
@BDate,
@Edate),
@BDate)
INTO #
Temp
FROM dbo.dt_article
--更新日期
UPDATE dbo.dt_article
SET add_time
=b.random_datetime
FROM dbo.dt_article a ,#
Temp b
WHERE a.id
=b.id