Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2007-08-24 : 01:41:23
|
| the following sql is taking a long time to runhow can I improve it?select count(vw.p) from vw where p not in (select p from payments where p is not null) and p not in(select p from cancelled where p is not null) and p not in (select p+site from reminders where p is not null) and vw.Psent<getDate()-14 |
|
|
shallu1_gupta
Constraint Violating Yak Guru
394 Posts |
Posted - 2007-08-24 : 01:49:47
|
| Hi,you can put a single not in statement with others combined with union allselect count(vw.p) from vw where p not in (select p from payments where p is not null union all select p from cancelled where p is not null union all select p+site as p from reminders where p is not null)and vw.Psent<getDate()-14 |
 |
|
|
billwork
Starting Member
0 Posts |
Posted - 2007-08-24 : 02:22:00
|
| thanks much faster... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-24 : 05:33:39
|
[code]select count(vw.p)from vwwhere and vw.Psent < DATEADD(DAY, DATEDIFF(DAY, 13, CURRENT_TIMESTAMP), 0) and not exists (select * from payments where payments.p = vw.p) and not exists (select * from cancelled where cancelled.p = vw.p) and not exists (select * from reminders where reminders.p + reminders.site = vw.p)[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|