vendredi 9 février 2018

Convert Excel VBA IF statement to SQL Select

Very new to SQL, so hopefully this is not an insultingly easy question but I’ve been struggling for two days. I need to convert the below If statement and into a select field AS [Status]. Any help is VERY appreciated. Also please excuse me - I’m doing this from my phone since work does now allow me to post to message boards, so I can’t wrap the code in a block

Dim i As Integer
  Dim j As Integer

  For i = 3 To 87 'from the first nonhead row to the last row, 87 is the #row of this specific example
   Cells(i, "DH").Value = ""
   If Cells(i, "B").Value > 20161231 Then 'check if the date    is after December
  If Cells(i, "AZ").Value = 0 Then 'check current loan amount
    If Cells(i, "cp").Value = "P" Or Cells(i, "cp").Value = "PL".     Then 'check Disposition Type Code when =p and pl
      If Cells(i - 1, "AY").Value = Cells(i, "AY") Then 'set paid in month m-1
        Cells(i - 1, "DH").Value = "Paid" 'set status in current month, m
      End If
    ElseIf Cells(i, "cp").Value = "FC" Then 'check Disposition Type Code when =fc
      If Cells(i - 1, "AY").Value = Cells(i, "AY") Then 'set status in previous month, m-1
        Cells(i - 1, "DH").Value = "D"
      End If
    End If 'end of checking Disposition Type Code
  ElseIf Cells(i, "AZ").Value > 0 Then 'when current loan amount >0
    If Cells(i, "CA").Value = "B" Or Cells(i, "CA").Value = "F" Then 'check loan status code
      Cells(i, "DH").Value = "D"
    Else
      If Cells(i, "BR").Value = "Y" Then 'check bankruptcy code
        Cells(i, "DH").Value = "D"

      Else
        If Cells(i, "ck").Value = "Y" Then 'check REO flag
          Cells(i, "DH").Value = "D"
        Else
          If Cells(i, "DF").Value > 0 And Cells(i, "DF").Value < 30 Then 'check calculated delinquency
            Cells(i, "DH").Value = "Current"
          ElseIf Cells(i, "DF").Value < 60 Then
            Cells(i, "DH").Value = "30DPD"
          ElseIf Cells(i, "DF").Value < 90 Then
            Cells(i, "DH").Value = "60DPD"
          Else
            Cells(i, "DH").Value = "D"
          End If 'end of checking calculated delinquency

        End If 'end of REO flag
      End If 'end of bankruptcy code
    End If 'end of current loan amount
  End If 'end of loan status code
End If 'end of checking date

Next i

End Sub

Aucun commentaire:

Enregistrer un commentaire