I am currently running the below code through SQL Server Management Studio queries before I implement it in my Django-Python application.
I am having trouble figuring out how to reference the database in question before the if statement begins:
Query:
If Age1 IS NULL 
    set @Current = DCBalance
    Select Account, Name, E-mail , Age1 , Age2 , Age3 , Age4 , Age5 , @Current ,DCBalance from [Graceland Estates BC].[dbo].[_avCustomerAging]
Else  Age1 IS NOT NULL
    If UADebit <> '0' and DCBalance > 0 
        Set @Current = DCBal - Sum(Age1, Age2, Age3 , Age4, Age5)
        Select Account , Name , E-mail , Age1 , Age2 , Age3 , Age4 , Age5 , @Current , DCBalance from [Graceland Estates BC].[dbo].[_avCustomerAging]
    Else  UADebit = '0'  and DCBalance < 0 
        Set @Age1X = fForeignBalance + Age1 - FCAge1
        Set @Age2X = fForeignBalance + Age2 - FCAge2
        Set @Age3X = fForeignBalance + Age3 - FCAge3
        Set @Age4X = fForeignBalance + Age4 - FCAge4
        Set @Age5X = fForeignBalance + Age5 - FCAge5
        Set @Current = 0
        Select Account , Name , E-mail , @Age1X , @Age2X , @Age3X , @Age4X , @Age5X , @Current , DCBalance
    Else  UADebit = '0'  and DCBalance > 0 
        Set @Ages = '0'
        Select Account , Name , E-mail , @Ages , @Ages , @Ages , @Ages , @Ages , DCBalance as Current , DCBalance
In the above code, it is meant to determine if the data matches what is represented in the if statement and do a calculation based on the way the data is displayed.
Here is the code when I try the same thing with a CASE expression:
Select Account, Name , EMail, Age1 AS Cur, Age2 , Age3 , Age4, Age5 ,DCBalance,
Case 
    When AccountLink = NULL Then Age1 = DCBalance and Age2 = 0 and Age3 = 0 and Age4 = 0 and Age5= 0
    When UADebit <> 0 and DCBalance > 0 Then Age1 = DCBalance - (Age2 + Age3 + Age4 + Age5)
    When UADebit = 0 and DCBalance < 0 Then Age1 = 0 and Age2 = fForeignBalance + Age2 - FCAge2 and Age3 = fForeignBalance + Age3 - FCAge3 and Age4 = fForeignBalance + Age4 - FCAge4 and Age5 = fForeignBalance + Age5 - FCAge5
    When UADebit = 0 and DCBalance > 0 Then Age1 = DCBalance and Age2 = 0 and Age3 = 0 and Age4 = 0 and Age5= 0
End 
From [Kyle].[dbo].[_avCustomerAging]
The error:
Incorrect syntax near '='.
is returned when this is executed