Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


finding the people who have a missing data item


finding the people who have a missing data item

Author
Message
chilidogie
chilidogie
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
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 !!!!
J-F Bergeron
J-F Bergeron
Say Hey Kid
Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)Say Hey Kid (711 reputation)

Group: General Forum Members
Points: 711 Visits: 2707
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! Wink

Cheers,

J-F
chilidogie
chilidogie
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
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 ?
andrewd.smith
andrewd.smith
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1222 Visits: 3232
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


chilidogie
chilidogie
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
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 !!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search