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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 complicated (for me) query/view

Author  Topic 

christappan
Starting Member

1 Post

Posted - 2010-10-10 : 00:01:35
I've got an application in which contact notes are entered by our case managers with various types of data, including the Individual's ID to whom it's related, the contact date and a code for contact type (TC-Telephone Call, HV-Home Visit, OV-Other Visit, etc.).

I need to build a SQL query/view that will show, for each case number, the last several (let's say 3) notes that had particular codes selected.

The final product would show, in one grid, the Individual's ID and last 5 Dates for the particular codes. I know this isn't making sense, so here's the visual:

Code:

Ind ID |Last HV |2 Ago HV |3 Ago HV |Last OV |2 Ago OV |3 Ago OV

I've actually been able to piecemeal queries and views together to produce this, but as we add more contact note records, the queries are highly inefficient.

I'm not educated or experienced in database design, so I know there's ways to do it, but this one's way over my head--can anyone offer suggestions? Thanks in advance.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-10 : 05:40:41
We need table structure (the create statement), sample data and wanted result in relation to the sample data.
With the (not) given information nobody is able to offer suggestions.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-11 : 12:10:14
are you using sql 2005?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -