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>-- Description:<擷取日期時間唯一編號>-- 調用方式:EXECUTE dbo.e_get_datetimestrguid;-- =============================================ALTER PROCEDURE [dbo].[e_get_datetimestrguid]-- Add the parameters for the stored procedure hereASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.-- Declare the return variable hereDECLARE @t_dt varchar(30);declare @rd_num float;declare @rd_str varchar(10);-- Add the T-SQL statements to compute the return value hereset @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 ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:<hsg>-- Create date: <2012-12-27>-- Description:<擷取日期時間唯一編號>-- 調用方式:select dbo.a_get_datetimestrguid();-- =============================================ALTER FUNCTION [dbo].[a_get_datetimestrguid]()RETURNS varchar(30)ASBEGIN-- Declare the return variable hereDECLARE @t_dt varchar(30);declare @rd_num float;declare @rd_str varchar(10);-- Add the T-SQL statements to compute the return value hereset @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 functionRETURN @t_dt;END