create table #Temp
(
testID int
testID int
)
select object_id('tempdb..#Temp')
select object_id('tempdb..#Temp')
SELECT top 10 OBJECT_ID FROM tempdb.sys.columns WHERE object_id = object_id('#Temp')
select * from #Temp
declare @counter_val int = 0
WHILE ( SELECT COUNT(*) FROM tempdb.sys.columns WHERE object_id = object_id('tempdb..#Temp')) < 1000
BEGIN
set @counter_val = @counter_val + 1
DECLARE @SQL NVARCHAR(MAX)
declare @fieldname nvarchar(20)
SET @fieldname = 'niraj' + cast(@counter_val as nvarchar(10))
SET @SQL = 'ALTER TABLE #Temp
ADD [' + CAST(@fieldname AS VARCHAR(10)) + '] varchar(30)'
--PRINT @SQL
EXECUTE (@SQL)
END
drop table #Temp
No comments:
Post a Comment