How to make columns to be selected by user

(3 posts) (2 voices)

Tags:

  1. mooncoldy, Member

    I create report parameter vColumns(checkbox which includes all column names) for user selecting some columns. And I create "columns_all_tmp" temporary table in code to store all column names. Then I want to use dbr.hidecolumn filter columns that user doesn't choose as below.

    select 'dbr.hidecolumn' union select Name from columns_all_tmp where Name not in (vColumns);

    But it doesn't work and all columns are shown. Does anyone have any suggestions? Thanks a lot.

  2. myDBR Team, Key Master

    Hi,
    in order to evaluate vColumns correctly, you need to use dynamic SQL:

    set @vSQL = concat("select 'dbr.hidecolumn', name from columns_all_tmp where name not in (", vColumns, ')');
    
    prepare stmt from @vSQL;
    execute stmt;
    deallocate prepare stmt;

    If you use vColumns directly, it will be evaluated as one string instead of list of strings.

    --
    myDBR Team

  3. mooncoldy, Member

    It works. Thanks.


Reply

You must log in to post.