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-06-16 : 12:06:12
|
| I have my column names right but its telling me they are invalid. It must be something to do with how I have my subquery formatted but I don't see it. I was wondering if anyone else can see it? It tells me payer_id is not right and I know its coming from the bolded section. I just added that line to do some additional grouping. I know that the query above aliased as D was working before I put the bolded line in. Am I setting this up wrong?select distinct c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestampfrom PersonMIA tmp join person a on a.person_id = tmp.person_idjoin patient_encounter b on a.person_id = b.person_idjoin provider_mstr c on b.rendering_provider_id = c.provider_idcross apply(select top 1 payer_name from person_payer where person_id = tmp.person_id order by payer_id) d join payer_mstr e on d.payer_id = e.payer_idjoin mstr_lists f on e.financial_class = f.mstr_list_item_id where c.description = 'Leon MD, Enrique'group by c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestamp)tmp2where year(create_timestamp) IN (2005,2006)group by person_nbr,payer_name,first_name,last_name,description,create_timestampThanks in Advance!Sherri |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-16 : 12:08:11
|
quote: Originally posted by sross81 I have my column names right but its telling me they are invalid. It must be something to do with how I have my subquery formatted but I don't see it. I was wondering if anyone else can see it? It tells me payer_id is not right and I know its coming from the bolded section. I just added that line to do some additional grouping. I know that the query above aliased as D was working before I put the bolded line in. Am I setting this up wrong?select distinct c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestampfrom PersonMIA tmp join person a on a.person_id = tmp.person_idjoin patient_encounter b on a.person_id = b.person_idjoin provider_mstr c on b.rendering_provider_id = c.provider_idcross apply(select top 1 payer_id,payer_name from person_payer where person_id = tmp.person_id order by payer_id) d join payer_mstr e on d.payer_id = e.payer_idjoin mstr_lists f on e.financial_class = f.mstr_list_item_id where c.description = 'Leon MD, Enrique'group by c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestamp)tmp2where year(create_timestamp) IN (2005,2006)group by person_nbr,payer_name,first_name,last_name,description,create_timestampThanks in Advance!Sherri
you dont have payer_id returned from derived table d. Add it inside like shown above. |
 |
|
|
sross81
Posting Yak Master
228 Posts |
Posted - 2008-06-16 : 14:22:56
|
I can't believe I didn't catch that. I get so lost when I start putting in all these subqueries. I will have to pay more careful attention to that. Thanks!quote: Originally posted by visakh16
quote: Originally posted by sross81 I have my column names right but its telling me they are invalid. It must be something to do with how I have my subquery formatted but I don't see it. I was wondering if anyone else can see it? It tells me payer_id is not right and I know its coming from the bolded section. I just added that line to do some additional grouping. I know that the query above aliased as D was working before I put the bolded line in. Am I setting this up wrong?select distinct c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestampfrom PersonMIA tmp join person a on a.person_id = tmp.person_idjoin patient_encounter b on a.person_id = b.person_idjoin provider_mstr c on b.rendering_provider_id = c.provider_idcross apply(select top 1 payer_id,payer_name from person_payer where person_id = tmp.person_id order by payer_id) d join payer_mstr e on d.payer_id = e.payer_idjoin mstr_lists f on e.financial_class = f.mstr_list_item_id where c.description = 'Leon MD, Enrique'group by c.description,tmp.person_id,tmp.person_nbr,tmp.first_name,tmp.last_name,tmp.date_of_birth,d.payer_name,b.create_timestamp)tmp2where year(create_timestamp) IN (2005,2006)group by person_nbr,payer_name,first_name,last_name,description,create_timestampThanks in Advance!Sherri
you dont have payer_id returned from derived table d. Add it inside like shown above.
Thanks in Advance!Sherri |
 |
|
|
|
|
|
|
|