Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join two seperate SQL into one

Status
Not open for further replies.

Wolfdzn

IS-IT--Management
Dec 11, 2013
98
CA
how can I join following two SQL into one? The data is in the same Avaya CMS Informix table.

1. data needed from yesterday 1/26/2022 b/w 19:00 and 2400

2.data needed form today 1/27/2022 b/w 0000 and 07:00



select row_date, starttime,starttime_utc, split,acdcalls from hsplit where split=11 and row_date>=TODAY and starttime<=700



Database selected.



row_date starttime starttime_utc split acdcalls

01/27/2022 0 1643259600 11 0
01/27/2022 30 1643261400 11 0
01/27/2022 100 1643263200 11 0
01/27/2022 130 1643265000 11 0
01/27/2022 200 1643266800 11 0
01/27/2022 230 1643268600 11 0
01/27/2022 300 1643270400 11 0
01/27/2022 330 1643272200 11 0
01/27/2022 400 1643274000 11 0
01/27/2022 430 1643275800 11 0
01/27/2022 500 1643277600 11 0
01/27/2022 530 1643279400 11 0
01/27/2022 600 1643281200 11 0
01/27/2022 630 1643283000 11 0
01/27/2022 700 1643284800 11 0

15 row(s) retrieved.



Database closed.

select row_date, starttime,starttime_utc, split,acdcalls from hsplit where split=11 and row_date>=TODAY-1 and starttime>=1900
!

Database selected.



row_date starttime starttime_utc split acdcalls

01/26/2022 1900 1643241600 11 0
01/26/2022 1930 1643243400 11 0
01/26/2022 2000 1643245200 11 0
01/26/2022 2030 1643247000 11 0
01/26/2022 2100 1643248800 11 0
01/26/2022 2130 1643250600 11 0
01/26/2022 2200 1643252400 11 0
01/26/2022 2230 1643254200 11 0
01/26/2022 2300 1643256000 11 0
01/26/2022 2330 1643257800 11 0

10 row(s) retrieved.
 
UNION / UNION ALL. More here. Alternative: modify WHERE conditions in single query.

combo
 
>modify WHERE conditions in single query.

[pre]
select row_date, starttime, starttime_utc, split, acdcalls
from hsplit
where split=11 [blue]
and (row_date >= TODAY and starttime <= 700)
or (row_date >= TODAY-1 and starttime >= 1900)[/blue]
[/pre]


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Date/time condition works, however it is pulling all splits including split 11

select row_date, starttime, split, acdcalls
from hsplit
where split=11
and (row_date >= TODAY and starttime <= 700)
or (row_date >= TODAY-1 and starttime >= 1900)
!

Database selected.



row_date starttime split acdcalls

01/30/2022 1900 11 0
01/30/2022 1930 11 0
01/30/2022 2000 11 0
01/30/2022 2030 11 0
01/30/2022 2100 11 0
01/30/2022 2130 11 0
01/30/2022 2200 11 0
01/30/2022 2230 11 0
01/30/2022 2300 11 0
01/30/2022 2330 11 0
01/30/2022 1900 12 0
01/30/2022 1930 12 0
01/30/2022 2000 12 0
01/30/2022 2030 12 0
01/30/2022 2100 12 0
01/30/2022 2130 12 0
01/30/2022 2200 12 0
01/30/2022 2230 12 0
01/30/2022 2300 12 0
01/30/2022 2330 12 0
01/30/2022 1900 13 0
01/30/2022 1930 13 0
01/30/2022 2000 13 0
01/30/2022 2030 13 0
01/30/2022 2100 13 0
01/30/2022 2130 13 0
01/30/2022 2200 13 0
01/30/2022 2230 13 0
01/30/2022 2300 13 0
01/30/2022 2330 13 0
01/30/2022 1900 14 0
01/30/2022 1930 14 0
01/30/2022 2000 14 0
01/30/2022 2030 14 0
01/30/2022 2100 14 0
01/30/2022 2130 14 0
01/30/2022 2200 14 0
01/30/2022 2230 14 0
01/30/2022 2300 14 0
01/30/2022 2330 14 0
01/30/2022 1900 15 0
01/30/2022 1930 15 0
01/30/2022 2000 15 0
01/30/2022 2030 15 0
01/30/2022 2100 15 0
01/30/2022 2130 15 0
01/30/2022 2200 15 0
01/30/2022 2230 15 0
01/30/2022 2300 15 0
01/30/2022 2330 15 0
01/30/2022 1900 16 0
01/30/2022 1930 16 0
01/30/2022 2000 16 0
01/30/2022 2030 16 0
01/30/2022 2100 16 0
01/30/2022 2130 16 0
01/30/2022 2200 16 0
01/30/2022 2230 16 0
01/30/2022 2300 16 0
01/30/2022 2330 16 0
01/30/2022 1900 17 0
01/30/2022 1930 17 0
01/30/2022 2000 17 0
01/30/2022 2030 17 0
01/30/2022 2100 17 0
01/30/2022 2130 17 0
01/30/2022 2200 17 0
01/30/2022 2230 17 0
01/30/2022 2300 17 0
01/30/2022 2330 17 0
01/30/2022 1900 18 0
01/30/2022 1930 18 0
01/30/2022 2000 18 0
01/30/2022 2030 18 0
01/30/2022 2100 18 0
01/30/2022 2130 18 0
01/30/2022 2200 18 0
01/30/2022 2230 18 0
01/30/2022 2300 18 0
01/30/2022 2330 18 0
01/31/2022 0 11 0
01/31/2022 30 11 0
01/31/2022 100 11 0
01/31/2022 130 11 0
01/31/2022 200 11 0
01/31/2022 230 11 0
01/31/2022 300 11 0
01/31/2022 330 11 0
01/31/2022 400 11 0
01/31/2022 430 11 0
01/31/2022 500 11 0
01/31/2022 530 11 0
01/31/2022 600 11 0
01/31/2022 630 11 0
01/31/2022 700 11 0

95 row(s) retrieved.
 
Additional pair of brackets is necessary, 'or' should be executed before first 'and':

[pre]WHERE split=11 AND ((row_date >= TODAY AND starttime <= 700) OR (row_date >= TODAY-1 AND starttime >= 1900))[/pre]

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top