Santosh,
Here is how I have done it (for Oracle database). It is little tricky though :-).
When we use TimePicker in dashboard, it returns time range (info_max_time & info_min_time). So you need to change your query to use both upper and lower range. You need to use "addinfo" command to get info_max_time & info_min_time. Once you have those 2 fields, you can analyse the return values with TimePicker selection.
e.g. info_max_time would have "+Infinity", when we select "All time". Both info_max_time & info_min_time would return epoch time (Unix time number / counts every seconds on and after 1 January 1970 ) for other selection.
So you need to construct your query in such a way that if you have All time selected then not to apply date criteria. For this reason, you need to construct your query dynamically.
Let's take your query (removed few fields for simplicity):
<query>| dbquery "CENTRO" "SELECT ShowRoomCode FROM Centro_Customer_Visit WHERE TransDate='$TOKEN2$'"</query>
and construct dynamically:
<query>|dbquery "CENTRO" [search index=main| head 1 | addinfo | eval query=IF(info_max_time="+Infinity","SELECT ShowRoomCode FROM Centro_Customer_Visit","SELECT ShowRoomCode FROM Centro_Customer_Visit WHERE TransDate between (sysdate - ( (((sysdate - to_date('01-Jan-1970', 'dd-Mon-yyyy')) * 86400) - ".info_min_time.")/86400)) and (sysdate - ( (((sysdate - to_date('01-Jan-1970', 'dd-Mon-yyyy')) * 86400) - ".info_max_time.")/86400))")|fields query|format "" "" "" "" "" ""]</query>
You might need to use appropriate command in MS SQL SERVER (may be getDate() ) instead of sysdate in Oracle).
I hope this will help. Let me know.
Thanks,
Sanjay
... View more