views:

24

answers:

2

Hi,

I have 3 tables:

Countries:

Code, Name

Vacances:

id(autoincrement),CountryCode, NameOfCountry, numberOfdays

How to foreach country insert Row:

countryCode,'Welcome in " + nameofCountry +"!",12
+3  A: 

No need for a loop or "foreach"...

INSERT Vacances (CountryCode, NameOfCountry, numberOfdays)
SELECT countryCode, 'Welcome in ' + Name + '!', 12
FROM Countries
gbn
Sorry, added some text to your instead of mine :-) I removed it..it was the sentence about SET based
SQLMenace
+3  A: 

try this

    insert Vacances(CountryCode, NameOfCountry, numberOfdays)
    select distinct  [Code],'Welcome to ' + [Name] +'!',12
    from Countries

No need for loops, databases are optimized for SET based operations, take advantage of that

SQLMenace