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 |
|
ohiocort
Starting Member
5 Posts |
Posted - 2009-09-30 : 17:21:29
|
Hello,I have searched through the forums and the internet but think my problem is too specific.I'm connecting to SQL Server using a DQY (created by someone else) and here is my old SQL code that works fine:SELECT 'Meds In Charts but NOT in History' as Note, tblResult.name as Patient, tblResultItems.name as Medication, tblResultItems.description as Prescription, cast(tblResult.date as date) as [Treatment date], [User].lastname as Nurse FROM tblResultItems JOIN tblResult ON tblResultItems.tblResultid=tblResult.ID join [User] ON tblResultItems.edituser = [User].useridnumber where [type]='Medication' AND isNull(DoneNotDonePostpone,0)=1 AND tblResultItems.RxID Not IN (Select MedPrescIDNumberFROM RunMedsActualAdministered WHERE RunIDNumber = tblResult.RunIDNumber) AND tblResult.date Between ? AND ?I wante to add one more element and thought I could do it by creating a SELECT within the SELECT like so:SELECT 'Meds In Charts but NOT in History' as Note, tblResult.name as Patient, tblResultItems.name as Medication, tblResultItems.description as Prescription, cast(tblResult.date as date) as [Treatment date], [User].lastname as Nurse, (SELECT Clinic.Name FROM Clinic join Patient ON Clinic.AssociationIDNumber=Patient.DefaultClinic where Patient.patientid = tblResult.patientid) AS Facility FROM tblResultItems JOIN tblResult ON tblResultItems.tblResultid=tblResult.ID join [User] ON tblResultItems.edituser = [User].useridnumber where [type]='Medication' AND isNull(DoneNotDonePostpone,0)=1 AND tblResultItems.RxID Not IN (Select MedPrescIDNumberFROM RunMedsActualAdministered WHERE RunIDNumber = tblResult.RunIDNumber) AND tblResult.date Between ? AND ?But when running this I receive: The multi-part identifier "tblResult.date" could not be bound.Any help?Thanks!Cort-yes i'm a newbie  |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-01 : 01:21:36
|
| [code]SELECT 'Meds In Charts but NOT in History' as Note, tblResult.name as Patient, tblResultItems.name as Medication, tblResultItems.description as Prescription, cast(tblResult.date as date) as [Treatment date], [User].lastname as Nurse, (SELECT Clinic.Name FROM Clinic join Patient ON Clinic.AssociationIDNumber=Patient.DefaultClinic where Patient.patientid = tblResult.patientid) AS Facility FROM tblResultItems JOIN tblResult ON tblResultItems.tblResultid=tblResult.ID join [User] ON tblResultItems.edituser = [User].useridnumber where [type]='Medication' AND isNull(DoneNotDonePostpone,0)=1 AND tblResultItems.RxID Not IN (Select MedPrescIDNumberFROM RunMedsActualAdministered WHERE RunIDNumber = tblResult.RunIDNumber) AND tblResult.date Between ? AND ?[/code]do you have date field in tblResult table? |
 |
|
|
ohiocort
Starting Member
5 Posts |
Posted - 2009-10-01 : 01:57:03
|
| Yes, there is a date field in tblResult. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-01 : 02:06:10
|
| is query posted your full query? |
 |
|
|
ohiocort
Starting Member
5 Posts |
Posted - 2009-10-01 : 02:31:33
|
| Yes, that is it. Although it's included in a dqy file so there are some connection parameters before it but this is the entire SQL. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-01 : 02:34:26
|
| are you using sql 2008? if not cast(tblResult.date as date) wont work |
 |
|
|
ohiocort
Starting Member
5 Posts |
Posted - 2009-10-01 : 08:29:43
|
| My first snippet of code works fine using the cast. I also tried taking out the last line (between ? and ?) and that works ok. |
 |
|
|
ohiocort
Starting Member
5 Posts |
Posted - 2009-10-05 : 13:46:43
|
| I was able to get this working by using joins instead of a sub-select statement.Thanks for the responses. |
 |
|
|
|
|
|
|
|