--方法一---------------------------------------------------------------------

declare @sql as varchar(1000)
declare @i as int
set @i = 0
set @sql = 'create table tb ('
while @i <= 10
begin
  set @sql = @sql +
  '[' + convert(varchar(10),dateadd(day , @i , getdate()),120) + '] int ,'
  set @i = @i + 1
end
set @sql = left(@sql , len(@sql) - 1) + ') select * from tb'
exec(@sql)

--方法二---------------------------------------------------------------------

declare @sql as varchar(1000)
declare @i as int
set @i = 0
create table #tb( id int )
while @i <= 10
begin
 SET @sql = 'ALTER TABLE #tb ADD ['+ convert(varchar(10),dateadd(day , @i , getdate()),120) +'] NVARCHAR(100) NULL'
 execute (@sql)
 set @i = @i + 1
end
select * from #tb
drop table #tb

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-01
  • 2021-12-04
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案