开发者

Foreach in sql with static data

I have 3 tables:

Countries:

Code, Name

Vacances:

id(autoincrement),CountryCode, NameOfCountry, numberOfdays

H开发者_JS百科ow to foreach country insert Row:

countryCode,'Welcome in " + nameofCountry +"!",12


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


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

INSERT Vacances (CountryCode, NameOfCountry, numberOfdays)
SELECT countryCode, 'Welcome in ' + Name + '!', 12
FROM Countries
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜