如何用SQL语句实现如下格式的数据输入

发布网友 发布时间:2024-10-24 04:13

我来回答

3个回答

热心网友 时间:9分钟前

前面的用函数getdate()+后面create view v_RAND
as
select re=stuff(rand(),1,2,'')
go

create function f_RANDBH(@BHLen int)
returns varchar(50)
as
begin
declare @r varchar(50)
if not(isnull(@BHLen,0) between 1 and 50)
set @BHLen=10

lb_bh:
select @r=re from v_RAND
while len(@r)<@BHLen
select @r=@r+re from v_RAND
set @r=left(@r,@BHLen)

if exists(select * from '表名' with(xlock,paglock) where number1=@r)
goto lb_bh

return(@r)
end
go
-----------------
准备工作好了

你的number1的默认值设为:dbo.f_RANDBH(4) 这个根据你需要设随机数个数 char() 类型

------------
应该没问题了

热心网友 时间:3分钟前

select convert(varchar(12),getdate(),112)+convert(varchar(50),convert(numeric,(rand()*10000000000)))

热心网友 时间:7分钟前

select convert(varchar(12),getdate(),112)+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
+cast(ceiling(rand()*9) as char(1))
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com