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.
| Author |
Topic |
|
frozenx
Starting Member
2 Posts |
Posted - 2008-08-17 : 08:58:19
|
| Tables I need to use for this queryPatient (patientNo, patName, patAddr, DOB)Prescribed (patientNo, drugNo, unitsPerDay, startDate, finishDate)Other tablesWard (wardNo, wardName, wardType, noOfBeds)Contains (patientNo, wardNo, admissionDate)Drug (drugNo, drugName, costPerUnit)I'm looking to list the details of all patients and thier prescribed drugNo and number of units of their medication. I have only limited knowledge of SQL and how to get around this query is confusing me!Any help would be appreciated. Many thanks! :-) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-17 : 09:02:58
|
| [code]SELECT p.patientNo,p.patName,pr.drugNo,pr.unitsPerDay,pr.unitsPerDay * DATEDIFF(dd,pr.startDate, pr.finishDate) AS TotalUnitsFROM Patient pINNER JOIN Prescribed prON pr.patientNo=p.patientNo[/code] |
 |
|
|
frozenx
Starting Member
2 Posts |
Posted - 2008-08-17 : 09:04:28
|
| You absoloute legend! I'm going to go try it now on my test database, thanks very much. :-) |
 |
|
|
Deon Smit
Starting Member
47 Posts |
Posted - 2008-08-18 : 04:59:03
|
| Visakh16Why did you use inner join. Wouldn't just join alne word with that? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-18 : 05:01:45
|
quote: Originally posted by Deon Smit Visakh16Why did you use inner join. Wouldn't just join alne word with that?
Sorry didnt get you. Were you asking if JOIN is same as INNER JOIN? if yes, yup they are one and the same. I just specified the type of join explicitly. thats all. |
 |
|
|
|
|
|
|
|