sql views and functions; import from Clavis improved