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 |
|
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 saysMsg 102, Level 15, State 1, Line 20Incorrect 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_namefrom person ajoin patient_medication b on a.person_id = b.person_idjoin patient_encounter c on b.enc_id = c.enc_idjoin fdb_medication d on b.ndc_id = d.ndc_idjoin provider_mstr e on b.provider_id = e.provider_idjoin location_mstr f on b.location_id = f.location_idleft join patient_procedure g on c.enc_id = g.enc_idleft join diagnosis_code_mstr h on g.diagnosis_code_id_1 = h.diagnosis_code_idwhere d.dose_form_desc IN ((select distinct dose_form_desc from fdb_medicationwhere gcn = '94200'))c.create_timestamp >= '7/15/08' and c.create_timestamp <= '7/16/08' and f.location_name = 'CHC Soundview Clinic' anda.first_name <> 'Lady' and a.first_name <> 'Test'order by c.create_timestampThanks 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_namefrom person ajoin patient_medication b on a.person_id = b.person_idjoin patient_encounter c on b.enc_id = c.enc_idjoin fdb_medication d on b.ndc_id = d.ndc_idjoin provider_mstr e on b.provider_id = e.provider_idjoin location_mstr f on b.location_id = f.location_idleft join patient_procedure g on c.enc_id = g.enc_idleft join diagnosis_code_mstr h on g.diagnosis_code_id_1 = h.diagnosis_code_idwhere d.dose_form_desc IN((select distinct dose_form_descfrom fdb_medicationwhere gcn = '94200')) AND c.create_timestamp >= '7/15/08' and c.create_timestamp <= '7/16/08'and f.location_name = 'CHC Soundview Clinic' anda.first_name <> 'Lady' and a.first_name <> 'Test'order by c.create_timestamp |
 |
|
|
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_namefrom person ajoin patient_medication b on a.person_id = b.person_idjoin patient_encounter c on b.enc_id = c.enc_idjoin fdb_medication d on b.ndc_id = d.ndc_idjoin provider_mstr e on b.provider_id = e.provider_idjoin location_mstr f on b.location_id = f.location_idleft join patient_procedure g on c.enc_id = g.enc_idleft join diagnosis_code_mstr h on g.diagnosis_code_id_1 = h.diagnosis_code_idwhere d.dose_form_desc IN((select distinct dose_form_descfrom fdb_medicationwhere gcn = '94200')) AND c.create_timestamp >= '7/15/08' and c.create_timestamp <= '7/16/08'and f.location_name = 'CHC Soundview Clinic' anda.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 : 11:01:35
|
| I cheated :) it was not me, I used a tool |
 |
|
|
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 |
 |
|
|
|
|
|
|
|