Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

finding the people who have a missing data item Expand / Collapse
Author
Message
Posted Thursday, January 29, 2009 12:30 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 8:41 AM
Points: 27, Visits: 76
Our database of clients keeps the date of the clients' annual visit. However, some of them did not come for several years, then out of the blue came in in 2008. I need to query for the people that came in past years, but did not show up in 2007, only to reappear in 2008. They are considered reenrollees. Our current system will show the people who are new, with no past visits, or the people who are returning.

I have tried to use a where exists and where not exists queries to no avail....ny suggestions ?

I would need to find the people who did not have visits in 2007 but did have them in 2008. A bonus would be to identify those who also had visits before 2007 but not in 2007, only to return in 2008.

Thank you !!!!
Post #646292
Posted Thursday, January 29, 2009 1:08 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, September 19, 2013 6:00 AM
Points: 715, Visits: 2,706
Can you post the actual queries you are building, it could help. We also need the schema of the tables involved.

We do not know what tables you are using, or whatever field you are joining on, help us help you! ;)


Cheers,

J-F
Post #646326
Posted Thursday, January 29, 2009 1:44 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 8:41 AM
Points: 27, Visits: 76
my table consists of two columns, NAME and YEAR. When the person visits, we record their name the current year. The queries I used/came up are in the trash. I initially used

select name,year
from visit
where not exists
(select name,year
from visit
where year=2007)


and now that I see what I did, I assume that I need to have a table of just names and link it to the visits table so tht I can get those in the name table that dont have a corresponding 2007 entry in the visits table. Any ideas on how ?
Post #646364
Posted Thursday, January 29, 2009 4:12 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, October 24, 2012 2:12 PM
Points: 1,213, Visits: 3,232
The following query returns all the clients who visited in 2008 and the year that the client previously visited or NULL if their first visit was in 2008). If I understand your requirements correctly, you should be able to categorise your clients based on the results of this query.

SELECT V1.Name, PreviousYear = MAX(V2.Year)
FROM Visit V1
LEFT OUTER JOIN Visit V2 ON (V1.Name = V2.Name AND V2.Year < 2008)
WHERE (V1.Year = 2008)
GROUP BY V1.Name
ORDER BY V1.Name

Post #646511
Posted Friday, January 30, 2009 11:34 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 18, 2012 8:41 AM
Points: 27, Visits: 76
Thank you !!!! It works very well. I took it a step further and used your suggestion to select into a temp file, then took that temp file, joined it back to the originall file, and reselected to get only those with an active visit in 2008. The people not seen in 2008 are off the list. My end result is a list people active this year with their last date/year of activity. Perfect.

Little by little I learn...Thank you !!
Post #647212
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse