Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


There are special use cases where you need to enable the parameter Macros= true. Let's take a look at one such The parameter "macros=true" has a limitation when using the nested SQL queries. For example, consider the use case below :

When to use

If your SQL query is in such a case that you want to execute the inner query first so that it can act as input to the outer query, then you need to use this parameter. Basically, if the inner query is independent then you need to use this option. Please see a sample SQL below : 

Code Block
select 'ABC' as col3, id
from testtable a
where a.id = '{sql-query:dataSource=SQLSERVER|table=false}select id FROM testtable WHERE id = 347878201 {sql-query}'

When NOT to use


There are certain cases where your inner query expects value/input from the outer query. In these cases, you should not use this parameter. Please see the sample SQL below:Following is an example of a SQL query where the output of the outer query is fed as input to the inner query.

Code Block
select ap.directory_id,
CONCAT('{sql-query:dataSource=SQLSERVER|table=false}
use jiradbnew;
select user_name, directory_id, display_name, email_address, dir.directory_position
from cwd_user usr
join cwd_directory dir on dir."id" = usr."directory_id" and dir."id"= ', ap.DIRECTORY_ID, ' {sql-query}') as "JiraVal"
from cwd_group ap

The query first executes and generates output

Code Block
||directory_id  ||JiraVal ||
  |1  |{sql-query:dataSource=SQLSERVER|table=false}
use jiradbnew;
select user_name, directory_id, display_name, email_address, dir.directory_position
from cwd_user usr
join cwd_directory dir on dir."id" = usr."directory_id" and dir."id"= 1 {sql-query} |

The option output = wiki will render the inner SQL query and thereby produces the final output.

...


...

In this case, if we enable macros=true, the inner query executes first and hence it does not yield proper result.