Thursday, March 29, 2012

Can we get the Next Row Value ?

In SSRS 2005 we have First,Last and Previous functions which get the related values based on the use. I want to compare with the NEXT row value and print it according to my requirement.

My question is How do I get the Next Row Value. Please Help.

Could be tricky, however try using a protected variable in the Code view... something like this (untested):

protected myprevValue as string

public function setString(myString as string) as string

myprevValue = myString
return ""

end function

public function getString() as string
return myprevValue

end function

Then you use a hidden text box with the expression =setString(myString)

If you have multiple values or want to lookup by row number you can use a dictionary object to store and retrieve them.

No guarantees on this and placement of the text boxes are key. I have not tried this with getting the Next value however it did work for doing things like lookups against data outside of the current dataset.

cheers,

Andrew

|||

Hello Andrew,

I tried the way you explained but I was able to get the previous row value only. Is there any other way wherein we can get the Next row's field value.

Please help,

|||

Looking into the future is tough.

You have to iterate through the set once to store the values in a lookup dictionary object, and then iterate again to retrieve. This becomes unmanageable with many fields... hopefully you're only looking up a couple of values here. I have not tried this rownumber method - I was using it to look up descriptive names for keys.

1st table - will contain the set function in a textbox expression passing in the row number and value. This table can be hidden.

=setValue(RowNumber(Nothing),myfield.value)

2nd table - will contain the get function passing in the row number.

=getValue(RowNumber(Nothing)

Code Below

public dictLookup as new System.Collections.Generic.Dictionary(Of String, String)

Function setValue(value as object, value2 as object) as object

dictLookup.Add(value, value2)

return value

End Function

Function getValue(value as object) as object

If dictLookup.ContainsKey(value)

return dictLookup(value)

else

return value

end if

End Function

No comments:

Post a Comment