SQL Server select column while inserting -


this question part of insert statement in trying select value value can inserted column.

for example in table onlineservers, have columns:

id, serverid, onlinesince 

in second table importservers, have columns data (the lines after newyork , paris empty):

importservername newyork  london paris  tokyo 

this question related sql server.

in third table, look-up table called serverlookup, have these columns data:

id, servername 0   not specified 1   newyork 2   london 3   tokyo 4   munich 5   salzburg 

question: want have sql statement can select id '0' serverlookup table if value of column importservername empty.

what have far is:

insert onlineservers (serverid, onlinesince) select (     select id     serverlookup     serverlookup.servername = importservers.servername        or serverlookup.servername = '' ), getdate() importservers 

the problem facing if server name matched, returns row empty server name.

how can fix problem.

thanks

ps: forgive me if there typo in code

insert onlineservers select case importservername      when '' 0     else id end serverid, getdate() importedservers s  left join serverlookup l on s.importedservername = l.servername;  

this should it. left join every record importedservers , use case 0 importservername blank.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -