Vigilante001
A Jolly Fellow...
- Local time
- Today, 01:35
- Joined
- May 16, 2008
- Messages
- 28
VBA Nested SQL Efficiency (SOLVED)
Hello Gurus,
I have the following SQL code which gets the results I need. Unfortunately, it takes a long time to run. I am familiar enough with SQL to build complex queries, but in this case I'm not confident that I did so in the most efficient manner. Any suggestions on how to improve it?
Thanks for any help offered!
Hello Gurus,
I have the following SQL code which gets the results I need. Unfortunately, it takes a long time to run. I am familiar enough with SQL to build complex queries, but in this case I'm not confident that I did so in the most efficient manner. Any suggestions on how to improve it?
Code:
[COLOR=#943634]SELECT p.Date, p.FirstNameInt, p.LastNameInt, p.DOBChild, p.DatabaseID, p.InteractionType, s.[Phone Number][/COLOR]
[COLOR=#943634]FROM [Interaction Table] AS p INNER JOIN SampleData AS s ON p.DatabaseID = s.AutoNumber[/COLOR]
[COLOR=#943634]WHERE ((p.Date Between #2/1/2010# And #2/28/2010#) AND [/COLOR]
[COLOR=#943634](p.DatabaseID In[/COLOR] [COLOR=#00B050](SELECT b.DatabaseID [/COLOR]
[COLOR=#00B050] FROM[/COLOR] [COLOR=#E36C0A](SELECT a.databaseID, a.FirstNameInt, a.LastNameInt, a.txtBehind, a.UTD431331, a.chkUnassessed [/COLOR]
[COLOR=#E36C0A] FROM [Interaction Table] AS a [/COLOR]
[COLOR=#E36C0A] WHERE (a.Date Between #2/1/2010# And #2/28/2010#) AND [/COLOR]
[COLOR=#E36C0A] (a.InteractionType='visit' Or a.InteractionType='Assessed') AND [/COLOR]
[COLOR=#E36C0A] a.txtBehind=True[/COLOR]
[COLOR=#E36C0A] )[/COLOR] [COLOR=#00B050]AS b[/COLOR]
[COLOR=#00B050]WHERE b.DatabaseID NOT IN[/COLOR] [COLOR=#AC5208](SELECT t.DatabaseID [/COLOR]
[COLOR=#AC5208] FROM [Interaction Table] AS t [/COLOR]
[COLOR=#AC5208] WHERE (t.Date Between #12/1/2009# And #5/28/2010#) AND [/COLOR]
[COLOR=#AC5208] t.InteractionType = 'Post-Visit Call')[/COLOR]
[COLOR=#943634]) AND p.InteractionType='Visit')[/COLOR]
[COLOR=#943634]ORDER BY p.Date;[/COLOR]
Last edited: