加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

获取日期时间唯一编号 SQLServer存储过程和函数的写法

发布时间:2020-12-12 14:13:08 所属栏目:MsSql教程 来源:网络整理
导读:GO/****** Object: StoredProcedure [dbo].[e_get_datetimestrguid] Script Date: 12/27/2012 15:07:38 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:hsg-- Create date: 2012-12-27--
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,':','.',' ','');
	-- 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,'');
	-- Return the result of the function	
	RETURN @t_dt;
END

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读