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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 What am I doing wrong with this subquery?

Author  Topic 

sross81
Posting Yak Master

228 Posts

Posted - 2008-07-21 : 10:55:39
I am trying to use a subquery to get a distinct list to filter on. I think I just hava a syntax problem because when I run the code it says
Msg 102, Level 15, State 1, Line 20
Incorrect syntax near 'c'.

It takes me to the line right below my subquery. I got yelled at this last time I posted a question like this but I am not looking for code analysis here I just wanted to know if I have the subquery posited properly, parenthesis or whatever. If you have any questions that will make it easier to understand please feel free to ask. Thank you in advance! :)

select distinct c.enc_id,a.person_id, a.first_name + ' ' + a.last_name as fullname,
a.date_of_birth,b.rx_quanity, b.rx_refills,b.sig_desc,c.create_timestamp,
d.brand_name,d.generic_name,e.first_name + ' ' + e.last_name as provname,
e.other_lic_id,f.address_line_1,f.city,f.state,f.zip,f.phone,f.fax,h.diagnosis_code_id,
h.description,f.location_name
from person a
join patient_medication b on a.person_id = b.person_id
join patient_encounter c on b.enc_id = c.enc_id
join fdb_medication d on b.ndc_id = d.ndc_id
join provider_mstr e on b.provider_id = e.provider_id
join location_mstr f on b.location_id = f.location_id
left join patient_procedure g on c.enc_id = g.enc_id
left join diagnosis_code_mstr h on g.diagnosis_code_id_1 = h.diagnosis_code_id
where d.dose_form_desc IN
(
(select distinct dose_form_desc
from fdb_medication
where gcn = '94200')
)
c.create_timestamp >= '7/15/08' and c.create_timestamp <= '7/16/08'
and f.location_name = 'CHC Soundview Clinic' and
a.first_name <> 'Lady' and a.first_name <> 'Test'
order by c.create_timestamp

Thanks in Advance!
Sherri

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-07-21 : 10:57:21
select distinct c.enc_id,a.person_id, a.first_name + ' ' + a.last_name as fullname,
a.date_of_birth,b.rx_quanity, b.rx_refills,b.sig_desc,c.create_timestamp,
d.brand_name,d.generic_name,e.first_name + ' ' + e.last_name as provname,
e.other_lic_id,f.address_line_1,f.city,f.state,f.zip,f.phone,f.fax,h.diagnosis_code_id,
h.description,f.location_name
from person a
join patient_medication b on a.person_id = b.person_id
join patient_encounter c on b.enc_id = c.enc_id
join fdb_medication d on b.ndc_id = d.ndc_id
join provider_mstr e on b.provider_id = e.provider_id
join location_mstr f on b.location_id = f.location_id
left join patient_procedure g on c.enc_id = g.enc_id
left join diagnosis_code_mstr h on g.diagnosis_code_id_1 = h.diagnosis_code_id
where d.dose_form_desc IN
(
(select distinct dose_form_desc
from fdb_medication
where gcn = '94200')
) AND c.create_timestamp >= '7/15/08' and c.create_timestamp <= '7/16/08'
and f.location_name = 'CHC Soundview Clinic' and
a.first_name <> 'Lady' and a.first_name <> 'Test'
order by c.create_timestamp
Go to Top of Page

sross81
Posting Yak Master

228 Posts

Posted - 2008-07-21 : 10:58:45
LOL :) You are amazing. I just rearranged some code and deleted the 'And'. Thanks for catching that for me my eyes just were not seeing it. :)

quote:
Originally posted by rohitkumar

select distinct c.enc_id,a.person_id, a.first_name + ' ' + a.last_name as fullname,
a.date_of_birth,b.rx_quanity, b.rx_refills,b.sig_desc,c.create_timestamp,
d.brand_name,d.generic_name,e.first_name + ' ' + e.last_name as provname,
e.other_lic_id,f.address_line_1,f.city,f.state,f.zip,f.phone,f.fax,h.diagnosis_code_id,
h.description,f.location_name
from person a
join patient_medication b on a.person_id = b.person_id
join patient_encounter c on b.enc_id = c.enc_id
join fdb_medication d on b.ndc_id = d.ndc_id
join provider_mstr e on b.provider_id = e.provider_id
join location_mstr f on b.location_id = f.location_id
left join patient_procedure g on c.enc_id = g.enc_id
left join diagnosis_code_mstr h on g.diagnosis_code_id_1 = h.diagnosis_code_id
where d.dose_form_desc IN
(
(select distinct dose_form_desc
from fdb_medication
where gcn = '94200')
) AND c.create_timestamp >= '7/15/08' and c.create_timestamp <= '7/16/08'
and f.location_name = 'CHC Soundview Clinic' and
a.first_name <> 'Lady' and a.first_name <> 'Test'
order by c.create_timestamp



Thanks in Advance!
Sherri
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-07-21 : 11:01:35
I cheated :) it was not me, I used a tool
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2008-07-21 : 15:14:46
quote:
Originally posted by rohitkumar

I cheated :) it was not me, I used a tool



I want to cheat too!!!! What tool did you use?

Terry
Go to Top of Page
   

- Advertisement -