Dynamic variable creation in SAP Business one Query Generator

Following are sample query for Dynamic variable creation in SAP Business one for Query Generator Report:

1st Way
/**SELECT FROM [OPCH] T0 **/
DECLARE @DocDateFrom as DateTime
/* WHERE */

Set @DocDateFrom =  /* T0.DocDate */ ‘[%0]’

/**SELECT FROM [OPCH] T0 **/
DECLARE @DocDateTo as DateTime
/* WHERE */


Set @DocDateFrom =  /* T0.DocDate */ ‘[%1]’


2nd Way

DECLARE @FromDate VARCHAR(20)

DECLARE @ToDate VARCHAR(20)

SELECT TOP 1 @FromDate = CONVERT(VARCHAR, T0.DocDate, 112) FROM OPCH T0 WHERE T0.DocDate >= '[%0]' ORDER BY T0.DocDate ASC


SELECT TOP 1 @ToDate = CONVERT(VARCHAR, T0.DocDate, 112) FROM OPCH T0 WHERE T0.DocDate <= '[%1]' ORDER BY T0.DocDate DESC