Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

SQL Query - Ok its from a windows app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mithril - 18 Feb 2005 23:44 GMT
I think I need a nested query but here's the problem. I promise i've
exerted my meager brain power on this problem & ask this as a last
resot!

3 Tables
PatientTable
   PatActive, PatID
ProfileTable
   PatID, CodeID, OtherInfo, MedicineID
MedicineTable
   MedicineID MedicineInfo

I need a return from Table2 Info including the detailed child data from
Table3 [OtherInfo] where patient is active, however i only want rows
from Profile table where the element CodeID is MAX for each patient.

subquery is fine
SELECT MAX(ProfileTab.CodeID) AS CodeID , patienttable.patsurname FROM
(profileTable INNER JOIN patienttable ON profiletable.PatID=
patienttable.PatID) GROUP BY patienttable.patsurname HAVING
(patienttable.patactive = 1)

I had to add the Group by statement when I tried to add this into
another query.

I dont have direct access to the DB so cannot use stored queries.
mithril - 19 Feb 2005 03:19 GMT
I have a query that gets the desired results in ACCESS but now the
DataAdapter doesn't like it.

Internally it runs (from the wizard) but I cannot make a dataset from
it!?

man this is frustrating.

BTW the SQL I came up with is as follows
(note i discover I don't need table1)

SELECT Profiletable.propnameid, Profiletable.CodeID,
Profiletable.patientid, MedicineTable.MedicineInfo
FROM MedicineTableRIGHT JOIN (Profiletable INNER JOIN [SELECT
Profiletable.patientid, Max(Profiletable.CodeID) AS MaxOfCodeID
FROM Profiletable GROUP BY Profiletable.patientid]. AS E1 ON
Profiletable.CodeID = E1.MaxOfCodeID) ON MedicineTable.MedicineID =
Profiletable.MedicineID;
Ron Allen - 19 Feb 2005 17:39 GMT
mithril,
   In general the wizards don't handle joined results correctly as they
can't figure out how to write the Update/Insert/Delete commands from the
SELECT.  You can manually create a DataAdapter and run code to load the
resulting table into a DataSet though.

Ron Allen

> I have a query that gets the desired results in ACCESS but now the
> DataAdapter doesn't like it.
[quoted text clipped - 17 lines]
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.