Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL code wrong???

Status
Not open for further replies.

eussias

Programmer
Sep 25, 2001
97
AU
Can anyone see anything wrong with this SQL statement below?? I'm trying to find all patients who have a Hb higher at Week 12 than at Week 0. The query is running, but is not getting the results that are expected.

SELECT ClientInfo.[Client Number], ClientInfo.Surname, ClientInfo.Forename
FROM ClientInfo LEFT JOIN Blood ON ClientInfo.[Client Number] = Blood.[Client Number]
WHERE (((Blood.[Week Number])=12) AND ((Blood.[Hb])>=
(SELECT Blood.[Hb] FROM Blood WHERE Blood.[Week Number] = 0
AND ClientInfo.[Client Number] = Blood.[Week Number])));
 
Hi!

Try making two queries:

Query1

SELECT ClientInfo.[Client Number] Blood.[Hb] FROM Blood Inner Join ClientInfo On Blood.[Client Number] = Blood.[Client Number] Where Blood.[Week Number] = 0

Query2

SELECT ClientInfo.[Client Number], ClientInfo.Surname, ClientInfo.Forename
FROM (ClientInfo Inner JOIN Query1 ON ClientInfo.[Client Number] = Query1.[Client Number]) Inner Join Blood On Query1.[Client Number] = Blood.[Client Number] WHERE Blood.[Week Number] = 12 AND Blood.[Hb] >= Query1.[Hb]

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top