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)
 Simple Insert Statement

Author  Topic 

dba123
Yak Posting Veteran

90 Posts

Posted - 2005-11-07 : 02:25:34
INSERT INTO tbl_City

(CityName)
Values
('Alameda', 'Albany', 'Antioch', 'Bay Point', 'Berkeley', 'Bethel Island', 'Brentwood', 'Byron', 'Canyon',
'Castro Valley', 'Clayton', 'Concord', 'Crockett', 'Danville', 'Diablo', 'Discovery Bay', 'Dublin', 'El Cerrito',
'El Sobrante', 'Emeryville', 'Fremont', 'Hayward', 'Hercules', 'Kensington', 'Knightsen', 'Lafayette', 'Livermore',
'Martinez', 'Moraga', 'Mount Eden', 'Oakland', 'Oakley', 'Orinda', 'Pacheco', 'Piedmont', 'Pinole', 'Pittsburg', 'Pleasanton',
'Pleasant Hill', 'Point Richmond', 'Port Costa', 'Richmond', 'Rodeo', 'San Leandro', 'San Lorenzo', 'San Pablo',
'San Ramon', 'Sunol', 'Union City', 'Walnut Creek')

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-07 : 02:29:07
I guess this wont work for you..

you have to do somthing like this ..

Insert Into Tbl_City(City)
Select 'Alameda'
Union All
Select 'Antioch'
.....
.....
Union All
Select 'Walnum Creek'



Complicated things can be done by simple thinking
Go to Top of Page

dba123
Yak Posting Veteran

90 Posts

Posted - 2005-11-07 : 02:33:46
what is the union doing in this case?
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-07 : 02:37:58
well according to the query which you have posted .. you want to insert the all the records in the column <city> .... so the records has to be in the rows format not in the column format ..

you have specified the records in the column format..

I guess you should look out for the Insert in boook online there you will get the better idea about it ..

Complicated things can be done by simple thinking
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-11-07 : 02:54:50
Yes, i use the union all statement a lot esp when you have to run multiple inserts into the same column.

But for dynamic values we use a while loop.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-07 : 03:41:35
>>what is the union doing in this case?

Refer Books On Line, SQL Server help file for more information

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-11-07 : 04:18:35
the union will give you a result that is similar to a table or array

if your values are delimited and passed into a parameter, you can use a split function, check the weblogs/forums for it

HTH

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -