refactor database name on sql server query