Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
Expand all | Collapse all

Varchar join not working with different character lengths

  • 1.  Varchar join not working with different character lengths

    Posted Thu April 14, 2022 05:01 PM
    I have two queries I need to join on location code.  Location code is an alphanumeric field between 4 and 6 characters. 

    In query one I'm using a case statement to bring in the location code so I'm having a problem with incompatible data types for the join.

    In both queries i'm doing:    cast ( [Location Code] , varchar(6) )

    The join will match on my location codes with 6 characters but not for location codes with 4 or 5 characters.

    Any advice on how to fix this?

    ------------------------------
    Jasmine D
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: Varchar join not working with different character lengths

    Posted Fri April 15, 2022 03:47 AM
    Edited by System Admin Fri January 20, 2023 04:42 PM
    Hi Jasmine,

    The first solution would be to create a Location code id that would be for instance:

    It should be quite easy if you can create new columns in both your tables.

    The other solution would be to create a technical column that would have the following expression in both your tables (in datamodule or Framework Manager):
    case length([Location Code])
    when 4 then '++' + [Location Code]
    when 5 then '+' + [Location Code]
    else [Location Code]
    end

    The result is the following:
    Then, you can create a join on the Location ID column.

    Best regards,

    ------------------------------
    Patrick Neveu
    Positive Thinking Company
    ------------------------------