Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

OR in the where clause or two select statements and a union

$
0
0
Howdy:I'm working a on script that contains an OR statement in the where clause. Below is the contents of the clause.[code="sql"]where ( enc.ADT_PAT_CLASS_C = '103' and enc.adt_arrival_time between dateadd(dd,-180,cast(getdate() as date)) and cast(getdate() as date) and enc.ed_episode_id is not null ) or ( enc.ADT_PAT_CLASS_C = '101' and enc.hosp_admsn_time between dateadd(dd,-180,cast(getdate() as date)) and cast(getdate() as date) )[/code]I've have seen ORs cause a hit to the performance of queries. I was wondering if I used two separate select statements one using the upper portion of the where clause and a second using the lower portion of the where clause with a union statement would decrease the running time of the query. So an example of the query would like this:[code="sql"]select *from blah [enc]where enc.ADT_PAT_CLASS_C = '103' and enc.adt_arrival_time between dateadd(dd,-180,cast(getdate() as date)) and cast(getdate() as date) and enc.ed_episode_id is not nullunionselect *from blah [enc] enc.ADT_PAT_CLASS_C = '101' and enc.hosp_admsn_time between dateadd(dd,-180,cast(getdate() as date)) and cast(getdate() as date)[/code]Any thoughts on this would be appreciated.Thanks,Ralph

Viewing all articles
Browse latest Browse all 3145

Trending Articles