View Full Version : Solved: Insert specified number of records with defined values
better
02-15-2006, 11:50 AM
Greetings All,
I'm new to this, and seem to be having trouble. I'm trying to insert a record a specified number of times, using a stored query with information being passed from an ASP application, but with no success. I have the insert query working both from within the database, and from the ASP app, using the following code:
INSERT INTO [Names] ( Name )
VALUES ([@newname]);
but get a syntax error when I try to save a new query in which I've added the TOP argument:
INSERT TOP (3) INTO [Names] ( Name )
VALUES ([@newname]);
Any ideas?
Thanks!
Bart
XLGibbs
02-15-2006, 12:12 PM
To do this is a little different syntax as the TOP 3 is for SELECT ...this syntax is what you need,
INSERT INTO [TABLE] ([Feild1],[Feild2]....etc)
Select Top 3 {Column} From {Table}
or something like..with your syntax..
Insert Into [Names] ( Name}
Select Top 3 @NewNAmes From [@NewName]
better
02-15-2006, 12:58 PM
INSERT INTO [TABLE] ([Feild1],[Feild2]....etc)
Select Top 3 {Column} From {Table}
This will actually be more appropriate for the full version of what I'm trying to do, so let me explain that more thoroughly, now that you've clarified that it can be done.
I have a DOORS table, with {DOOR} and about {20 other columns}.
I have a DOOR_DEFAULTS table, with {DEFAULTID} and {20 other columns}.
I presume I will need a DOORNOS table with {DOORNO}
My ASP application will pass NUMDOORS and DEFAULTID to the stored query, which will need to :
insert into (DOORS) (DOOR), (20 other columns)
select top ([@NUMDOORS]) (DOORNO) from (DOORNOS),
select (20 other columns) FROM (DOOR_DEFAULTS) WHERE (DEFAULTID) = ([@DEFAULTID])
Does that seem about right? I hope it's coherent enough to follow!
Thanks for the help!
Bart
XLGibbs
02-15-2006, 01:03 PM
Yes that makes sense
You just have to specify each column appropriately in the ( ) for the insert,
and then make sure your select statement has them in the same order...
better
02-16-2006, 07:33 PM
The TOP argument apparantly wasn't what I needed to accomplish what I wanted to do. I ended up handling it in my ASP code something thus:
WHILE Counter <> 0
Exec.insert
Counter = Counter - 1
Wend
Got that working, so now on to the next challenge.
Thanks for your help!
Bart
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.