获取日期时间唯一编号 SQLServer存储过程和函数的写法
2012-12-27 15:07
295 查看
GO /****** Object: StoredProcedure [dbo].[e_get_datetimestrguid] Script Date: 12/27/2012 15:07:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <hsg> -- Create date: <2012-12-27> -- Description: <获取日期时间唯一编号> -- 调用方式:EXECUTE dbo.e_get_datetimestrguid; -- ============================================= ALTER PROCEDURE [dbo].[e_get_datetimestrguid] -- Add the parameters for the stored procedure here AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. -- Declare the return variable here DECLARE @t_dt varchar(30); declare @rd_num float; declare @rd_str varchar(10); -- Add the T-SQL statements to compute the return value here set @t_dt=convert(varchar,getdate(),21); set @t_dt=replace(@t_dt,'-',''); set @t_dt=replace(@t_dt,':',''); set @t_dt=replace(@t_dt,'.',''); set @t_dt=replace(@t_dt,' ',''); -- Return the result of the function --生成一个椭机数 select @rd_num=floor(Rand()*99999); set @rd_str=convert(varchar,@rd_num); --合并一个 select @t_dt+@rd_str; END
/****** Object: UserDefinedFunction [dbo].[a_get_datetimestrguid] Script Date: 12/27/2012 14:33:29 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <hsg> -- Create date: <2012-12-27> -- Description: <获取日期时间唯一编号> -- 调用方式:select dbo.a_get_datetimestrguid(); -- ============================================= ALTER FUNCTION [dbo].[a_get_datetimestrguid] ( ) RETURNS varchar(30) AS BEGIN -- Declare the return variable here DECLARE @t_dt varchar(30); declare @rd_num float; declare @rd_str varchar(10); -- Add the T-SQL statements to compute the return value here set @t_dt=convert(varchar,getdate(),21); set @t_dt=replace(@t_dt,'-',''); set @t_dt=replace(@t_dt,':',''); set @t_dt=replace(@t_dt,'.',''); set @t_dt=replace(@t_dt,' ',''); -- Return the result of the function RETURN @t_dt; END
相关文章推荐
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- .net获取日期时间的各种格式的函数
- VC++获取当前系统时间日期 GetSystemTime()函数的用法
- JS代码获取当前日期时支持IE,不兼容FF和chrome,解决这个问题,我们需要把获取时间的getYear()函数换成getFullYear()
- 获取指定日期的随机时间(oracle函数)
- JS获取时间的相关函数及时间戳与时间日期之间的转换
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- MySQL获取时间及日期的函数--sysdate()
- JS代码获取当前日期时支持IE,不兼容FF和chrome,解决这个问题,我们需要把获取时间的getYear()函数换成getFullYear()
- Python获取时间范围内日期列表和周列表的函数
- ASP 时间函数及如何获取服务器时间的写法
- VC++获取当前系统时间日期 GetSystemTime()函数的用法
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- JS代码获取当前日期时支持IE,不兼容FF和chrome,解决这个问题,我们需要把获取时间的getYear()函数换成getFullYear()
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]
- ASP 时间函数及如何获取服务器时间的写法
- 前端PHP入门-022-重点日期函数之获取本地化时间戳函数.md
- 如何获取本地时间信息,并把getDay()函数获取到的日期改为日一二三四五六