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

  • I found the solution. I was misreading the error from the very start. I should have started to explain the problem from the root. I was trying to populate a field in maximo from JDE with data from 2 fields in JDE concatenated with a period between them. The first line of code I wrote looked like this

    CASE WHEN [ORDER_TYPE] = 'SS' or [ORDER_TYPE] = 'SP' THEN [BU] + '.' + [OBJECT]

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

    Message that came was:

    Error converting Varchar value '101202. ' to data type int. 101202 is one of the BU's but what I did not notice is the period after then the single quote. I then went about converting the BU, OBJECT and SUBSIDIARY to int and then all hell begun. What I needed to do was put single quotes on the 14350 and that could have solved the problem. After reading the posted replies, trying several times on Friday, I gave up and slept on it. Played a round of golf on Saturday and it came to me on the 11th hole (which I parred). Got home, tried it out and viola! So this is the final line that populated the GL account field as needed. Long way to do something but with it I learnt more things.

    CASE WHEN [ORDER_TYPE] = 'SS' or [ORDER_TYPE] = 'SP' THEN [BU] + '.' + [OBJECT]

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