网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > SQL技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.Proxy Server和SQL Server在上数.
.在SQL Server 2005中用存储过程实.
.深入探讨数据仓库建模与ETL的实践.
.Microsoft SQL Server备份和恢复.
.特殊数据(SQL).
.SQL Server的Collate语句需注意.
.sql server 查询分析器快捷键集合.
.如何随机选取n条记录或者对记录作.
.利用数据库复制技术 实现数据同步.
.SQL Server 2008与Microsoft数据.
.讲解SQL Server2005数据项的分拆.
.SQL Server 2005密码安全追踪与存.
.SQLServer分页查询通用存储过程.
.用一条SQL实现:一行多个字段数据.
.存储过程与SQL语句的恩怨情仇.
.比较一下看看自己掌握了多少SQL快.
.将Sql Server自增长字段的目前识.
.不能安装SQL Server 2005的问题及.
.标准SQL规范中定义的四个事务隔离.
.SQL Server中读取XML文件的简单做.

循环插入一定时间范围内的随机日期值

发表日期:2008-3-31


SQL Server中循环插入一定时间范围内的随机日期值

-- First, let's declare the date range. I am declaring this
     -- here for the demo, but this could be done anyway you like.
     DECLARE @date_from DATETIME;
     DECLARE @date_to DATETIME;
      
     -- Set the start and date dates. In this case, we are using
     -- the month of october, 2006.
     SET @date_from = '2006-10-01';
     SET @date_to = '2006-10-30';
      
     -- insert  random dates.
     insert into randomdate SELECT
     (
     -- Remember, we want to add a random number to the
     -- start date. In SQL we can add days (as integers)
     -- to a date to increase the actually date/time
     -- object value.
     @date_from +
     (
     -- This will force our random number to be GTE 0.
     ABS(
      
     -- This will give us a HUGE random number that
     -- might be negative or positive.
     CAST(
     CAST( NewID() AS BINARY(8) )
     AS INT
     )
     )
      
     -- Our random number might be HUGE. We can't have
     -- exceed the date range that we are given.
     -- Therefore, we have to take the modulus of the
     -- date range difference. This will give us between
     -- zero and one less than the date range.
     %
      
     -- To get the number of days in the date range, we
     -- can simply substrate the start date from the
     -- end date. At this point though, we have to cast
     -- to INT as SQL will not make any automatic
     -- conversions for us.
     CAST(
     (@date_to - @date_from)
     AS INT
     )
     )
     )
上一篇:详细讲解各种数据库使用JDBC连接的方式 人气:1977
下一篇:轻松解决SQL Server 2005中的常见问题 人气:1274
浏览全部sql server的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐