Changing VBA code - into - SQL statement

I have this code in Excel VBA:

If Cells(lngRow, ConstTASTMS_ActivateTime).Value < getdate() - 7 Then

      Cells(lngRow, ConstTASTimeClass).Value = "BOH"

      If Cells(lngRow, ConstTASTask_Status) = "Closed" Then

        If Cells(lngRow, ConstTASActual_EndDate).Value <= getdate() - 7 Then

          Cells(lngRow, ConstTASTimeClass).Value = "BOH-CO"

        Else

          Cells(lngRow, ConstTASTimeClass).Value = "BOH-C"

        End If
      End If

      If Cells(lngRow, ConstTASTask_StatusReason) = "Canceled" Then

        If Cells(lngRow, ConstTASActual_EndDate).Value <= getdate() Then

          Cells(lngRow, ConstTASTimeClass).Value = "BOH-XO"

        Else

          Cells(lngRow, ConstTASTimeClass).Value = "BOH-X"

        End If

      End If

    Else

      Cells(lngRow, ConstTASTimeClass).Value = "New"

      If Cells(lngRow, ConstTASTask_Status) = "Closed" Then Cells(lngRow, ConstTASTimeClass).Value = "New-C"

      If Cells(lngRow, ConstTASTask_Status) = "Canceled" Then Cells(lngRow, ConstTASTimeClass).Value = "New-X"

    End If


And now, I need to translate it into the SQL statement.
So far, I got this, and don't think it's correct.
Can someone please take a look and help me to correct it?


CASE WHEN TMS_ActivateTime < getdate() - 7 THEN

      TimeClass = "BOH"

      CASE WHEN Task_Status = "Closed" THEN

      CASE WHEN Actual_EndDate  <= getdate() - 7 THEN

      TimeClass  = "BOH-CO"

    ELSE

      TimeClass  = "BOH-C"
 
      CASE WHEN  Task_StatusReason = "Canceled" THEN

      CASE WHEN  Actual_EndDate  <= getdate() THEN

      TimeClass  = "BOH-XO"

        ELSE

      TimeClass  = "BOH-X"
       
    ELSE

      TimeClass  = "New"

      CASE WHEN  Task_Status = "Closed" THEN  TimeClass  = "New-C"

      CASE WHEN  Task_Status = "Canceled" THEN  TimeClass  = "New-X"

END
Mich MichBI LeadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
What flavor of SQL are you targeting, SQL Server, Oracle, Access, ...


»bp
0
Bill PrewCommented:
Okay, double check this, it should be what you had above in VBA.

SELECT CASE
           WHEN tms_activatetime < Getdate() - 7 THEN 
               CASE 
                   WHEN task_status = "closed" THEN 
                       CASE 
                           WHEN actual_enddate <= Getdate() - 7 THEN "boh-co" 
                           ELSE "boh-c" 
                       END 
                   WHEN task_statusreason = "canceled" THEN 
                       CASE 
                           WHEN actual_enddate <= Getdate() THEN "boh-xo" 
                           ELSE "boh-x" 
                       END 
                   ELSE "boh" 
               END 
           ELSE 
               CASE 
                   WHEN task_status = "closed" THEN "new-c" 
                   WHEN task_status = "canceled" THEN "new-x" 
                   ELSE "new" 
               END 
       END AS TimeClass

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mich MichBI LeadAuthor Commented:
Works PERFECT! Thanks Bill :-)
0
Bill PrewCommented:
Welcome, glad that helped.


»bp
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.