求一个MSSQL的存储过程中的循环语句,像是问题补充那样要求的。_百度...
发布网友
发布时间:2024-10-24 08:19
我来回答
共3个回答
热心网友
时间:2024-11-02 14:44
我看过你前一个问题,把代码修改为:
set @Flag = 1
do:
select @temp ='z'+ replace(replace(replace(convert(nvarchar(19),getdate(),121),'-',''),':',''),' ','')
while @Flag < 10
begin
set @id = @temp+convert(nvarchar,@Flag)
if not exists(select 1 from Info where InfoId = @id)
begin
insert into info values(这里是你要Insert的值)
end
set @flag=@flag+1
goto do
end
热心网友
时间:2024-11-02 14:37
declare @temp nvarchar(16)
select @temp ='z'+ replace(replace(replace(convert(nvarchar(19),getdate(),121),'',''),':',''),' ','')
declare @subfix int, @result nvarchar(17)
set @subfix = 1
while @subfix < 10
begin
set @result = @temp + cast( @subfix as nvarchar(1))
print @result
set @subfix = @subfix + 1
end
热心网友
时间:2024-11-02 14:37
declare @temp nvarchar(16),
@i int
set @i=1
while @i<10
begin
set @temp ='z'+ replace(replace(replace(replace(convert(nvarchar(19),getdate(),121),'',''),':',''),' ',''),'-','')
print @i
set @temp = @temp + convert(varchar(1),@i)
set @i=@i+1
print @temp
end