Showing posts with label lines. Show all posts
Showing posts with label lines. Show all posts

Thursday, March 29, 2012

Finding last instance of string

How can I find the last instance of a string? I was thinking of writing a
loop that goes through the string, but that requires writing a few lines of
code. I was also thinking of inverting the string (in this case, charindex
would work since). But I'm not sure how to invert the string w/o writing too
much code.
Any help is appreciated. Thanks.> But I'm not sure how to invert the string w/o writing too
> much code.
Check the REVERSE T-SQL function.
Dejan Sarka|||DECLARE @.s VARCHAR(32);
SET @.s = 'aoodfsdf';
SELECT LastInstanceOfA = CASE CHARINDEX('a', @.s)
WHEN 0 THEN 0
ELSE LEN(@.s) + 1 - CHARINDEX('a', REVERSE(@.s))
END;
"VMI" <VMI@.discussions.microsoft.com> wrote in message
news:109B0CEE-6424-4154-9ED3-7E56C2B41B7F@.microsoft.com...
> How can I find the last instance of a string? I was thinking of writing a
> loop that goes through the string, but that requires writing a few lines
> of
> code. I was also thinking of inverting the string (in this case, charindex
> would work since). But I'm not sure how to invert the string w/o writing
> too
> much code.
> Any help is appreciated. Thanks.

Sunday, February 19, 2012

Filtering Top n on Group or Table

Hopefully someone can help.

I am trying to filter either my group or the whole table to return the top 5 lines of my data.

If I use Topn (Fieldname) = 5 in my filter for the group, it returns merely the total of the table and hides all the detail.

If I use the same filter in the table filter, only the table header is returned.

I have rather a complex formula based on parameters to calculate the field I want to show the top 5 of. e.g. If parameter equals 2 then add balance_period_1 to balance_period_2. This formula works perfectly if I remove the top5 filter. See detailed expression below

The expression is

Topn(iif(Parameters!Period.Value = "02", Fields!Year_Opening_Balance. Value+Fields!Balance_Period_01.Value +Fields!Balance_Period_02.Value,0))

The Operator is set to =

The Value is set to 5

Any ideas would be greatly appreciated.

Set the filter expression to:
=iif(Parameters!Period.Value = "02", Fields!Year_Opening_Balance. Value+Fields!Balance_Period_01.Value +Fields!Balance_Period_02.Value,0))

Set the filter operator to:
TopN

Set the filter value to:
=5

Note: if you set the filter value to just 5, it will be interpreted as string constant - which won't work. You have to set it to =5, which will evaluate to the integer value 5.

-- Robert

|||

Thanks!!

So simple but blind to my eyes, now all is revealed!