Results 1 to 3 of 3

Thread: Check if recordset is populated

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    Check if recordset is populated

    Hi,

    I am trying to create a vb script in DTS that will succeed if the recordset is empty and will fail (and call an email function) if the recordset has any records. I am trying to use a if statement but not sure if am on the right path or there is a better way of doing this.

    Would appreciate if someone could assist.


    Dim connEWORK
    Const adOpenForwardOnly = 0
    Const adLockReadOnly = 1
    Const adCmdText = &H0001
    Const adOpenDynamic = 2
    Const adOpenKeyset = 1


    Function Main()

    Dim SQL
    Dim strRecipients
    Dim CheckForDiscrepancy

    Set connEWORK = CreateObject("ADODB.Connection")
    Set RS = CreateObject("ADODB.Recordset") connEWORK.Provider = "FGDSGDSGDS" connEWORK.Properties("Data Source").Value = "DGDSGDSGDSG" connEWORK.Properties("Initial Catalog").Value ="e-DGFSDSGDSGF" connEWORK.Properties("User ID").Value = "ewDSFGDDSork" connEWORK.Properties("Password").Value = "DSFGDSGDS" connEWORK.Properties("Integrated Security").Value = "FDGDSGDG" connEWORK.ConnectionTimeout = 5 connEWORK.commandtimeout = 5

    connEWORK.Open
    SQL = "select * from dbo.MDS_DuplicateRecords"
    RS.Open SQL, connEWORK, adOpenKeyset, adLockReadOnly, adCmdText
    RS.Close Set RS = Nothing
    connEWORK.Close Set connEWORK = Nothing

    If (RS isnull) Then
    Main = DTSTaskExecResult_Success

    Else

    Main = DTSTaskExecResult_Failure

    strRecipients = "FDSGDSFGDSGFDFG"

    Call sendEmail(strRecipients)

    End If

    End Function

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Name: Function Send_Email

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Function sendEmail(strRecipients)

    Dim iMsg

    Set iMsg = CreateObject("CDO.Message")

    With iMsg

    .To = strRecipients
    .From = "HAHA@HAHA"
    .Subject = "NNNNNNNNNNNNNNNNNNNN"

    ' Content of email

    .TextBody = "NNNNNNNNNNNNNNNNNNNNN" & vbCrLf & vbCrLf &_
    "NNNNNNNNNNNNNNNNNNNNNNNNNNN'" & vbCrLf & vbCrLf &_
    "NNNNNNNNNNNNNNNNNNNNNNN"

    .Send

    End With

    Set iMsg = Nothing

    End Function

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Check if recordset is populated

    connEWORK.Open
    SQL = "select * from dbo.MDS_DuplicateRecords"
    RS.Open SQL, connEWORK, adOpenKeyset, adLockReadOnly, adCmdText

    If rs.BOF and rs.EOF Then
    Main = DTSTaskExecResult_Success

    Else

    Main = DTSTaskExecResult_Failure

    strRecipients = "FDSGDSFGDSGFDFG"

    Call sendEmail(strRecipients)

    End If

    RS.Close Set RS = Nothing
    connEWORK.Close
    Set connEWORK = Nothing
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2010
    Posts
    61

    Re: Check if recordset is populated

    Thanks Gary. I'll give this a go and let you know how i get on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width