一、8位随机数据存储过程
/****** Object: StoredProcedure [dbo].[pro_rand8] Script Date: 2015-07-24 12:36:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[pro_rand8](@rand varchar(8)='8888888888888' out)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @str varchar(30)
set @str=convert(varchar(30),CONVERT(DECIMAL(20,20),rand()))
set @rand=SUBSTRING(@str,3,8)
END
二、年月日时分秒+8位随机数
declare @rand varchar(8)
execute pro_rand8
@rand=@rand output
select convert(varchar(19),getdate(),112)+DateName(hour,GetDate())+ DateName(minute,GetDate())+DateName(second,GetDate())+@rand as today
select DateName(hour,GetDate())+ DateName(minute,GetDate())+DateName(second,GetDate())