Good morning all
I've written the following query:
define AssetVar = "'BA G-ZBJA'"
define DateFromVar = "'12/08/2016 15:00:00'"
define AssetClause = " where Asset = &AssetVar";
define
BEGIN
IF DateFromVar = ""
Then define DateFromClause = ""
ELSE
define DateFromClause ="and DATETIME >= TO_DATE(&DateFromVar, 'dd/mm/yyyy hh24:mi:ss')";
End IF;
End;
define
select * from SCHEDULE &AssetClause &DateFromClause ;
undefine AssetVar DateFromVar AssetClause DateFromClause;
The theory is, the end user can set variables and the query will be built based on the variables set, if they set it to nothing, the if statement basically excludes that clause from the final query.
If I provide all variables and remove the IF everything is fine, I think the variables are not being passed into the IF correctly but I'm not sure
Has anyone ever achieved this or know why i's not working?