mercredi 27 octobre 2021

Referencing a database in if statements

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.

Aucun commentaire:

Enregistrer un commentaire