Home Forums SQL Server 2008 SQL Server 2008 - General Trying to use Case Statement to get value into a GL Account with periods in the format RE: Trying to use Case Statement to get value into a GL Account with periods in the format

  • How about this then:

    If GL Code is 19, the max possible length of the data will be 22 (7+8+5 + 2 full stops)!

    --BU is varchar(7)

    --SUBSIDIARY is varchar(8)

    --OBJECT is varchar(5)

    --GL Acct is GL(19)

    declare @a as table ([BU] Varchar(7), [ORDER_TYPE] Char(2), [SUBSIDIARY] Varchar(8), [OBJECT] Varchar(5));

    insert @a values ( 'BU1', 'SS', 'Slumpco', 'OBJ1' );

    insert @a values ( 'BU2', 'AA', 'Slumpco2', 'OBJ2' );

    select

    CASE

    WHEN [ORDER_TYPE] = 'SS' or [ORDER_TYPE] = 'SP'

    THEN [BU] + '.' + [OBJECT]

    ELSE

    [BU] + '.'+ '14350' + '.' + [SUBSIDIARY]

    END

    from @a