简体   繁体   中英

How can I set a data set parameter using two/combined parameters 1 date and 1 time with condition

This is my current query :

where cast(dateadd(h,cast(substring(case when timezoneoffset = 'Z' then '0' else timezoneoffset end,1,3) as int),cast(transactionendtime::timestamp as timestamp without time zone)) as date) >= ?
and cast(dateadd(h,cast(substring(case when timezoneoffset = 'Z' then '0' else timezoneoffset end,1,3) as int),cast(transactionendtime::timestamp as timestamp without time zone)) as date) <= ?

here are the parameters from my data set: 在此处输入图片说明

rp_startdate and rp_enddate data type is Date , required parameters
while rp_startTime and rp_endTime is Time value is 24 hour with hourly interval, also these are not required parameters
在此处输入图片说明 在此处输入图片说明

Now what I want is when the user didn't select starttime or endtime (Null Value) then my query stays like that only read the start and end date , But when the user selects starttime and endtime , then I want to query it to have a condition combine the startDate and endTime & endDate and endTime as DateTime , then on my query pass that use that two for the query

Additional info for queries:
Start and End Time = Null Value | Use Current Query
Same Date , StartTime = Null Value | Use Current Query
Same Date , EndTime = Null Value | Use Current Query
Same Date , Start and End Time = Not Null | Change Query to include time
Different Date , Start and End Time = Any Value | Use Current Query

You should handle this by converting both of the inputs to timestamps, but using NVL() to handle when the user doesn't enter the time:

Psuedocode:

WHERE cast(dateadd(h,cast(substring(case when timezoneoffset = 'Z' then '0' else timezoneoffset end,1,3) as int),cast(transactionendtime::timestamp as timestamp without time zone)) as date) BETWEEN (date(?) || ' ' || NVL(?, '00:00:00'))::TIMESTAMP AND (date(?) || ' ' || NVL(?, '23:59:59'))::TIMESTAMP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM