if exists (select ...from...where...)begin update tabset .....
esle begininsert into tbb ....from tba
if not exists (select ...from tbb)begin insert into tbb (......) select tba(....)