自定义sqlserver列名
set @num2 = 20
while(1=1)
begin
if @num2 = 0 break
else
begin
set @sql = N’alter table #a add ‘ + N’numName’ + cast( @num2 as nvarchar(30)) + N’ nvarchar(50)’
exec (@sql)
set @num2 = @num2 – 1
end
end
declare @bm nvarchar(30) –@bm为中文时前后需要录入单引号
set @sql =’ update #a set ‘ + ‘numName’ + cast(@num as nvarchar(30)) + ‘= N”’ + N” + @bm + ”’ where id = 1 ‘
exec (@sql)