SQL Server randomly generates a specified range of dates

Source: Internet
Author: User
Tags add time

A paging problem, DTCms3.0, paging is based on the time page, if the Add Time (add_time) is the same value, regardless of the number of pages clicked, the data displayed is the same content, so there is a need to change the same time to specify a random date function.

The original paste script goes to http://bbs.csdn.net/topics/340165720 on the 7th floor of Feilniu.

The SQL script is as follows:

DECLARE@BDatedatetime,@EDatedatetime
SET@BDate='20150701'--Lower Limit
SET@EDate='20150714 23:59:59'--Upper Limit
SELECTID, Random_datetime=DATEADD(Second,ABS(CHECKSUM (NEWID()))%DATEDIFF(Second,@BDate,@Edate),@BDate)
fromDbo.dt_article
WHEREIdbetween 1 and -


The resulting content is:

IdRandom_datetime

32015-07-05 07:55:10.00042015-07-08 06:15:06.00092015-07-12 19:14:24.000102015-07-11 20:13:05.000122015-07-06 19:09:12.000132015-07-09 10:28:59.000142015-07-03 07:18:42.000152015-07-06 09:46:29.000

The ID at this time is the ID in the corresponding dt_article table.

Then we can write the generated data to the temporary table, then associate the update!


SQL Server randomly generates a specified range of dates

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.