Forum Discussion

Kneelay's avatar
Kneelay
New Contributor II
9 months ago

SQL Table Insert Not adding all Records

HI All,  I'm running into an issue when running a Finance Business Rule, essentially this rule creates a data buffer and loops through where U8 member is not 0. From here we have a SQL statement wh...
  • RobbSalzmann's avatar
    RobbSalzmann
    9 months ago
    Dim valueList As List(Of String) = New List(Of String)
    Dim x As Integer = 0
    
    For Each Cell As DataBufferCell In SrcDataBuffer.DataBufferCells.Values
        ' Execute If Allocation percentage Is Not equal To 0
        If Cell.CellAmount <> 0 Then			            
            x += 1
            sAcct = Cell.DataBufferCellPk.GetAccountName(api)
            sUD1 = Cell.DataBufferCellPk.GetUD1Name(api)
            sFlow = Cell.DataBufferCellPk.GetFlowName(api)
            sUD2 = Cell.DataBufferCellPk.GetUD2Name(api)
            sUD4 = Cell.DataBufferCellPk.GetUD4Name(api)
    		valueList.Add($"('{sqlentity}','{sEntitymember}', '{sUD4}', '{sFlow}', '{sUD2}', '{sUD1}', '{sAcct}', {Cell.CellAmount})")
        End If
    Next
    
    Dim insertValues = String.Join(", ", valueList)
    
    Dim sql As String = $"INSERT INTO XFT_BSM_Mapping_Total$ 
                         ([BU], [Entity], [BSM_Account], [BSM_Measure], [Responsibility_Center], [Company_Code], [Account],[Allocation_Percentage])
                         VALUES {insertValues}"
    brapi.ErrorLog.LogMessage(si,x)
    
    Using dbConn As DBConnInfo = BRAPi.Database.CreateApplicationDBConnInfo(si)
    	BRAPi.Database.ExecuteSql(dbConn , sql, True)
    End Using