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
 Transact-SQL (2000)
 Statement to Insert a range of items

Author  Topic 

ramoneguru
Yak Posting Veteran

69 Posts

Posted - 2006-07-25 : 20:44:37
I have a query like this..

INSERT INTO Persons (Last, Period)
Values ('Jones', '12')

INSERT INTO Persons (First, Period)
Values ('Smart', '12')

INSERT INTO Persons (First, Last, Middle, Period)
Values ('Richards','12')

and so on....
I'm only modifying one field and keeping the second one the same. Is there a way I can do this insert without using like 900 seperate INSERT statements?? So something along the lines of this:

INSERT INTO Persons (First, Period)
VALUES ('<Range of names here>', '12')

Is that possible??
--Nick

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-07-25 : 21:02:31
[code]
INSERT INTO Persons (Last, Period)
select
Name, '12'
from
(
select Name = 'Jones' union all
select 'Smart' union all
select 'Richards' union all
... and so on until the end...
select 'Zman'
) a


[/code]

CODO ERGO SUM
Go to Top of Page

ramoneguru
Yak Posting Veteran

69 Posts

Posted - 2006-07-26 : 13:12:21
Sweeeeeet, thanks MVJ
--Nick
Go to Top of Page
   

- Advertisement -