I am new to SQL Server (2008 R2) and I am trying to create a view for use with a web app built with Dreamweaver.
Just to provide an example of what I am looking for, I want a listing of all the Clients who visited on 7/14/2009, and their most current address. I have seen some examples of using max, but they were incomplete and when I try to put them together using only two tables I can make it work, but when I try to do multiple tables like below, I keep getting aggregate errors. Here is an example of how I would like to see the list:
Currently, using a straightforward view, I am getting a complete line for each name for each address, and my inexperience with SQL Server is a bit frustrating. The list that I am creating is a bit larger and has more fields but I am showing these few for simplicity. If I can get it figured out for these, then I should be able to apply it to the remainder.
BTW the reason for the separate addresses table is for a current change to have an address history for each case and for each client.
Anticipating your responses. Thanks in advance for your help.
gh
Just to provide an example of what I am looking for, I want a listing of all the Clients who visited on 7/14/2009, and their most current address. I have seen some examples of using max, but they were incomplete and when I try to put them together using only two tables I can make it work, but when I try to do multiple tables like below, I keep getting aggregate errors. Here is an example of how I would like to see the list:
Code:
Case_ID EnrollDate Name Address VisitDate 3 7/14/2009 Tom 412 Seville 7/14/2009 3 7/14/2009 Susan 412 Seville 7/14/2009 1 6/1/2009 Mary 325 Sandy 7/14/2009 1 6/1/2009 Bob 325 Sandy 7/14/2009 2 6/5/2009 Bill 704 Mallard 7/14/2009
BTW the reason for the separate addresses table is for a current change to have an address history for each case and for each client.
Code:
Table Case Case_ID EnrollDate 1 6/1/2009 2 6/5/2009 3 7/14/2009 4 7/29/2009 Table Clients ID Case_ID Name 3 1 Mary 4 1 Bob 11 2 Bill 15 3 Tom 16 3 Susan 27 4 Harry Table Addresses Addr_ID Case_ID Address 1 1 123 Main 2 2 215 Hillary 3 3 885 Montrose 4 2 704 Mallard 5 1 325 Sandy 6 4 207 Avendia 7 3 412 Seville Table Visits V_ID Case_ID VisitDate 1 1 6/1/2009 2 2 6/5/2009 3 3 7/14/2009 4 1 7/14/2009 5 4 7/29/2009 6 2 7/14/2009 7 3 7/26/2009
gh
Comment