Execute queries on a database before writing to SQL Server