I want to select data from following tables for a Jasper report.
DDL + DML
CREATE TABLE SLPAYROLL_LIVE.dbo.AA_COLUMN_NAMES(
id int PRIMARY KEY NOT NULL,
name varchar(500) NOT NULL,
active bit
);
INSERT INTO SLPAYROLL_LIVE.dbo.AA_COLUMN_NAMES (id, name, active) VALUES (1, 'col_1', 1);
INSERT INTO SLPAYROLL_LIVE.dbo.AA_COLUMN_NAMES (id, name, active) VALUES (2, 'col_2', 1);
INSERT INTO SLPAYROLL_LIVE.dbo.AA_COLUMN_NAMES (id, name, active) VALUES (3, 'col_3', 1);
INSERT INTO SLPAYROLL_LIVE.dbo.AA_COLUMN_NAMES (id, name, active) VALUES (4, 'col_4', 0);
CREATE TABLE SLPAYROLL_LIVE.dbo.AA_PAYMENT_DETAILS(
id int PRIMARY KEY NOT NULL,
username varchar(500),
col_1 varchar(500),
col_2 varchar(500),
col_3 varchar(500),
col_4 varchar(500)
);
INSERT INTO SLPAYROLL_LIVE.dbo.AA_PAYMENT_DETAILS (id, username, col_1, col_2, col_3, col_4) VALUES (1, 'chathura', '500', '200', '300', '0');
INSERT INTO SLPAYROLL_LIVE.dbo.AA_PAYMENT_DETAILS (id, username, col_1, col_2, col_3, col_4) VALUES (2, 'gihan', '300', '100', '100', '0');
I want to select only active columns from AA_PAYMENT_DETAILS
. The active column names can be get from the AA_COLUMN_NAMES
table.
I have googled my question and found the following solution.
Select columns from one table based on the column names from another table
Since I want to use that query in a Jasper Report, above solution does not worked. Does anyone know a solution?