updated sql to distinguish legacy from impc dataset