vbscript: Function DeltaImportsPending

To use with Delta imports from SQL – check if there are any lines in the Delta table before running an Import. By only running delta imports when there’s actually something to do you can save on time and transaction log space.

Const DB_CONNECT_STRING = “Provider=SQLOLEDB;Data Source=(local);Initial Catalog=DB-name;Integrated Security=SSPI”

‘  Function DeltaImportsPending
‘  + Returns TRUE if the Delta table has content

Function DeltaImportsPending(Delta_Table)
  Dim objDB, sqlQuery, recordset

  Set objDB = CreateObject(“ADODB.Connection”)
  Set recordset = CreateObject(“ADODB.Recordset”)

  sqlQuery = “SELECT COUNT (*) AS num FROM ” & Delta_Table

  recordset.Open sqlQuery, objDB

  If recordset.Fields(“num”) > 0 Then
    DeltaImportsPending = TRUE
    DeltaImportsPending = FALSE
    WriteLog(“No pending delta imports – stopping.”)
  End If


End Function