Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 insert without cursor

Author  Topic 

skillile
Posting Yak Master

208 Posts

Posted - 2002-01-17 : 22:21:59
If I have a form calling a sproc and the data are values and #of times to insert that value. ie.

value, 2x
value, 1x
value, 4x
value, 6x

I want to put them into a table such as:

create table (value varchar(xx))

how do I put the records in this table when the value could be anywhere from 0-50 without using a cursor and without doing something like:

if @x=1
begin
while ...
begin
insert ....

end
end

if @x=2
begin
while
begin
insert ...
end
end


slow down to move faster...

fisherman_jake
Slave to the Almighty Yak

159 Posts

Posted - 2002-01-18 : 01:15:13
My friend, this would require for you to have a table with one field and the values of this field will be 1,2,3,4,...,N. N is your forseen upper limit (ie from your spec... value, Nx). Now say you called this table [MULTICOUNT], and the only field called [CountID] then your latest and greatest discovery would be:

--<TSQL>--
Insert TARGETTABLE
Values(value)
From MULTICOUNT
Where N >= CountID
--<TSQL>--

This will insert "value", N number of times..

Now where is that beer..

I love this JOB..

==================================================
World War III is imminent, you know what that means... No Bag limits!!!
Master Fisherman
Go to Top of Page
   

- Advertisement -