Sql server compare tables, stored and functions