SSRS 2008 substring process

  • In an SSRS 2008 existing report, I have one column that I need to separate the values. I am not allowed to change the database. I am told that I need to work with the data as it is.

    The values in the column look like the following

    099 11-12 Midwest Plumbers.

    I need to split the data to look like

    1. 099 is the Customer Number.

    2. 11-12 is the year the customer data was valid.

    3. Midwest Plumbers is the name of the company.

    Notes:

    1. The delimiter between the 3 fields is " " (one space).

    2. The company name can contain lots of spaces.

    3. There are 3 fields that need to be separated out which are:

    a. Customer Number,

    b. Effective Years,

    c. Customer Name.

    I 'best' solution, I have so far is:

    =Mid(Parameters!pCust.Value,InStr(Parameters!pCust.Value," ") + 1,Len(Parameters!pCust.Value)-Instr(Parameters!pCust.Value," ")).

    However the above only gets me the first value.

    Thus can you show me how to split up the in this column within SSRS?

  • wendy elizabeth (11/1/2013)


    In an SSRS 2008 existing report, I have one column that I need to separate the values. I am not allowed to change the database. I am told that I need to work with the data as it is.

    I don't know the syntax of SSRS but here's what works in T-SQL. You would need to replace SUBSTRING with MID and CHARINDEX with the equivalent (INSTR?) SSRS function. CHARINDEX finds the position of the first expression in the second expression starting at the optional third express)

    Here's a working example. Of course, you could change @SomeString to the column name you want to parse and add a FROM clause for the table that column exists in but I wanted to keep this simple. They COULD add persisted computed columns to the table to permanently split the data without any changes to a well written front-end.

    In the following, the only assumption that I made about the data is that the CustomerNumber column will ALWAYS be 3 characters as indicated by the leading zero's. Heh... having such formatted customer numbers is yet another mistake the people that designed this made. This is a really strange requirement because they want normalized data to appear in the report but refuse to normalize the data in the database where it should be.

    DECLARE @SomeString VARCHAR(100);

    SELECT @SomeString = '099 11-12 Midwest Plumbers';

    SELECT CompanyNumber = SUBSTRING(@SomeString,1,3)

    ,ValidYear = SUBSTRING(@SomeString,5,CHARINDEX(' ',@Somestring,CHARINDEX(' ',@SomeString,5))-5)

    ,CompanyName = SUBSTRING(@SomeString,CHARINDEX(' ',@SomeString,5)+1,8000)

    ;

    Here are the results...

    CompanyNumber ValidYear CompanyName

    ------------- --------- ----------------

    099 11-12 Midwest Plumbers

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • wendy elizabeth (11/1/2013)


    In an SSRS 2008 existing report, I have one column that I need to separate the values. I am not allowed to change the database. I am told that I need to work with the data as it is.

    The values in the column look like the following

    099 11-12 Midwest Plumbers.

    I need to split the data to look like

    1. 099 is the Customer Number.

    2. 11-12 is the year the customer data was valid.

    3. Midwest Plumbers is the name of the company.

    Notes:

    1. The delimiter between the 3 fields is " " (one space).

    2. The company name can contain lots of spaces.

    3. There are 3 fields that need to be separated out which are:

    a. Customer Number,

    b. Effective Years,

    c. Customer Name.

    I 'best' solution, I have so far is:

    =Mid(Parameters!pCust.Value,InStr(Parameters!pCust.Value," ") + 1,Len(Parameters!pCust.Value)-Instr(Parameters!pCust.Value," ")).

    However the above only gets me the first value.

    Thus can you show me how to split up the in this column within SSRS?

    Hi,

    Try the split function

    a. Customer Number,

    =(Split(Parameters!pCust.Value," ")).GetValue(0)

    b. Effective Years,

    =(Split(Parameters!pCust.Value," ")).GetValue(1)

    c. Customer Name.

    =Trim(Replace(Replace(Parameters!pCust.Value,(Split(Parameters!pCust.Value," ")).GetValue(0)," "), (Split(Parameters!pCust.Value," ")).GetValue(1), " " ))

    edit: changed fields to parameters

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply