Maximo Open Forum

 View Only
  • 1.  SQL Split GL Account field into separate columns

    Posted 8 days ago

    Looking for some assistance in creating a SQL query to split the GL Account field Value into separate columns by GL segment.  For example:  If my code block consists of 6 segments split by a - as a delimiter and I would like to query and return the information into individual columns by segment.  


    #EverythingMaximo
    #Integrations
    #Reporting

    ------------------------------
    Adam Olson
    Deriva Energy
    ------------------------------


  • 2.  RE: SQL Split GL Account field into separate columns

    Posted 8 days ago

    The SQL query varies a little based on which database you are using. Are you on Oracle/SQL Server/DB2.Based on your database,I can send you a sample script.

    Thanks



    ------------------------------
    Mahadevan Ramakrishnan
    ------------------------------



  • 3.  RE: SQL Split GL Account field into separate columns

    Posted 6 days ago

    SQL Server



    ------------------------------
    Adam Olson
    Deriva Energy
    ------------------------------



  • 4.  RE: SQL Split GL Account field into separate columns

    Posted 8 days ago

    Hi,

    I may have misunderstood your request, but when I run the following query in SQL Server, I get the screenshot result, which shows each GL Component in separate columns.

    SELECT *
    FROM chartofaccounts c
    where active = 1 AND glaccount LIKE 'p4%'



    ------------------------------
    Stevie Holloway
    Tufts University
    ------------------------------



  • 5.  RE: SQL Split GL Account field into separate columns

    Posted 7 days ago

    You could join the main table like workorder with the chartofaccounts table to retrieve the records.
    Example:

    select wo.glaccount,ca.glcomp01,ca.glcomp02,ca.glcomp03,ca.glcomp04 from workorder wo 
    inner join chartofaccounts ca on wo.glaccount=ca.glaccount and wo.orgid=ca.orgid
    where wo.wonum='WO12345';



    ------------------------------
    Sankar Ganesh V S
    DXC Technology
    ------------------------------



  • 6.  RE: SQL Split GL Account field into separate columns

    Posted 7 days ago

    Try this:

    SELECT GLACCT, 
        PARSENAME(REPLACE(GLACCT,'-','.'),6)AS PART1,
        PARSENAME(REPLACE(GLACCT,'-','.'),5)AS PART2,
        PARSENAME(REPLACE(GLACCT,'-','.'),4)AS PART3,
        PARSENAME(REPLACE(GLACCT,'-','.'),3)AS PART4,
        PARSENAME(REPLACE(GLACCT,'-','.'),2)AS PART5,
        PARSENAME(REPLACE(GLACCT,'-','.'),1)AS PART6
    FROM TABLE 



    ------------------------------
    gail smith
    chevron
    ------------------------------



  • 7.  RE: SQL Split GL Account field into separate columns

    Posted 6 days ago

    Gail, thanks for the help, the function does work as expected, but we have "." characters within our component values and the parsename function appears to use the . to split which is causing it to successfully execute.  Any other ideas?  I did add an example of a code structure

    test1-test2-test3-test4-test5.100.10-test6



    ------------------------------
    Adam Olson
    Deriva Energy
    ------------------------------



  • 8.  RE: SQL Split GL Account field into separate columns

    Posted 6 days ago

    Adam, replace the periods with a dummy value like a pipe,|, first (just some character you would never find in your data), then replace the dashes to periods, let it parse, then replace the end result's pipes back to periods.  I put the new replaces in lowercase to show where to put them.

     

    replace(PARSENAME(replace(REPLACE(GLACCT, '.' , '|' ), '-' , '.' ),6), '|' , '.' )AS PART1