sql - Transfer Data from One table to Another Table based on a condition -


i have table name sourcetable fields rollid, smsid, fname, lname. destination table desttable field id, firstname , lastname. task creat desttable data of sourcetable following condition:

if rollid = null    id = smsid else    id = rollid end if 

fname go firstname , lname go lastname

what statement should write?

this should it:

insert desttable (id, firstname, lastname)    select coalesce(rollid,smsid), fname, lname    sourcetable 

you can read coalesce here:

http://msdn.microsoft.com/en-us/library/ms190349.aspx


Comments