ssrs-2008commentsminquery-designer

Is there a way to only select the first comment imputed for each record?


I have a dataset that consists of CommentDateTime, CommentCode, Comment and CommentKey. There are multiple comments per a CommentCode but I only want the first comment created for each CommentCode to show up in my report.

Is there a way to do this?

I am new to SSRS so I am sorry if I didn't explain my question super well.


Solution

  • Unless I'm missing something, it would be better to do this in your dataset query so that only the first comment is returned rather then sending lots of data to the report and then writing expressions to filter it out.

    Something like

    SELECT a.CommentDateTime, a.CommentCode, a.Comment, a.CommentKey 
        FROM (
            SELECT 
                    CommentDateTime, CommentCode, Comment, CommentKey,
                    ROW_NUMBER() OVER(PARTITION BY CommentCode ORDER BY CommentDateTime) as RowN
            FROM @myTable
            ) a 
        WHERE a.RowN = 1
    

    This assumes CommentKey is unique to each comment. WHERE a.RowN = 1