sql - How to insert a list of numbers after an existing list of numbers -


i have column in database store pin numbers survey. list of numbers 5100 - 6674. need keep pin numbers there current survey have add new list of pin numbers same column. want make sure query have created insert new list column without affecting old list. there column gives survey type. need add new type new list example, have list of pins ranging 5100 - 6674 survey type of cln. next list range of numbers 8100 - 8855 survey type of tm. not want mess current survey running have 1 shot right, otherwise there big mess. here query have come with.

declare @pin int set @pin = 8100 while (@pin <= 8855) begin     insert survey (pin) values (@pin)     select @pin = @pin + 1     survey     pin > 6674 end  update survey set type = 'tm' pin > 6674 

thank or advice.

i suggest set type @ same time pin , fix increment step:

declare @pin int; set @pin = 8100; while (@pin <= 8855) begin     insert survey(pin, type)         values (@pin, @type);      set @pin = @pin + 1; end; 

you can single statement, if want learn bit more sql:

with pins (       select 8100 pin       union       select pin + 1       pins       pin < 8855   ) insert survey(pin, type)     select pin, 'tm'     pins; option (maxrecursion 10000); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -