I have requirement in my project to extract the rows in sql format. I have multiple select statements with same WHERE condition. Is it possible to set the WHERE condition in a param and make use of it in the select statements?
@set maxrows -1;
@export on;
@export set filename="C:\test\test12.sql" appendfile="true" format="sql";
SELECT ee.employeeId, ee.firstname, ee.lastName, ee.designation
FROM employee ee
WHERE ee.employeeId in (1, 2, 3, 4);
SELECT lib.employeeId, lib.bookId
FROM library lib
WHERE lib.employeeId in (1, 2, 3, 4);
SELECT lv.employeeId, lv.LeaveApplicationDate, lv.NoOfLeaves
FROM Leaves lv
WHERE lv.employeeId in (1, 2, 3, 4);
@export off;
As you can observe here, the WHERE condition is constant for each of SELECT Statements. Is it possible to set in a param and make use of the same in all the select statements?
Example (below will not work):
@set maxrows -1;
@set employeeIds = 1, 2, 3, 4;
@export on;
@export set filename="c:\Work\test124536.sql" appendfile="true" format="sql";
SELECT ee.employeeId, ee.firstname, ee.lastName, ee.designation
FROM employee ee
WHERE ee.employeeId in (employeeIds);
@export off;