COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: yogeswari on 07 Nov 2013 04:01:54 AM

Title: Extract a string from a word
Post by: yogeswari on 07 Nov 2013 04:01:54 AM
Hi All,

Can anyone provide solutions for the issue:

Column Values=ASP-000123 or it can be
                        AMP-000123 or it can be
                        BP Initial-000123 or it can be
                        BP Restated-000123
Required=>000123

I need to extract ASP if the value is (ASP-000123) But answer should come 000123
I need to extract AMP if the value is (AMP-000123) But answer should come 000123
I need to extract BP Initial if the value is (BP Initial-000123) But answer should come 000123
I need to extract BP Restated if the value is (BP Restated-000123) But answer should come 000123

How to do this?
I tried by using substring and Trim function but Trim function removes single character only.  I need to remove set of characters or string of values.

Could please anyone provide solution as will consider your help as Great

Thanks,
Yogeswari.

Title: Re: Extract a string from a word
Post by: BigChris on 07 Nov 2013 04:34:24 AM
From your sample data it looks like the number you're looking for is always preceded by "-". You should be able to FIND that character and use that as the starting point for your substring. It depends on what platform you're using, but if you're using SQL server you probably want to use something like CHARINDEX.

C
Title: Re: Extract a string from a word
Post by: Grim on 07 Nov 2013 08:11:45 AM
If the numbers you want are always 6 characters and depending on what DB you are using you should be able to just do a...
right([CommonValue], 6)

You can also try...
substring([CommonValue], -6)
Title: Re: Extract a string from a word
Post by: yogeswari on 08 Nov 2013 09:12:18 AM
Hi All,

Thank you so much for your responses :).  I tried by using Substring and Trim function.
Its works fine.

Thank you all your responses.  Will get back to you if anything i struggle.

Thanks,
Yogeswari.