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
 General SQL Server Forums
 New to SQL Server Programming
 Finding TaxID with dup products

Author  Topic 

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-10-03 : 08:59:43
I am not sure how to go about asking this. I have a database that imported multiple products under a tin. I was wondering how I can go about find all of them. What I am thinking is....Give me all taxid (pcsa_tax1)that have duplicate products "DGH" (pcsp_prd). Not sure if this is enough information for you.

TaxID 2459872548
BROOKLYN PEDIATRIC ASSOCIATES

DEVON DGH EFF: 06/01/2003 TRM: PHYFEE BCD
DEVON DGH EFF: 05/15/2003 TRM: PHYFEE BCD

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-10-03 : 09:30:15
This is what I have so far.


select * from VW_Double_Pricing
where PCSA_tax1 in (

Select Distinct
PCSA_tax1

From VW_Double_Pricing
where pcsp_prd = 'DGH'
group by PCSA_tax1

HAVING COUNT (pcsp_prd) > 1)
order by pcs_lname
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 09:40:57
quote:
Originally posted by werhardt

I am not sure how to go about asking this. I have a database that imported multiple products under a tin. I was wondering how I can go about find all of them. What I am thinking is....Give me all taxid (pcsa_tax1)that have duplicate products "DGH" (pcsp_prd). Not sure if this is enough information for you.

TaxID 2459872548
BROOKLYN PEDIATRIC ASSOCIATES

DEVON DGH EFF: 06/01/2003 TRM: PHYFEE BCD
DEVON DGH EFF: 05/15/2003 TRM: PHYFEE BCD




SELECT taxid
FROM YourTable t
JOIN (SELECT pcsp_prd
FROM YourTable
GROUP BY pcsp_prd
HAVING COUNT(*) >1)tmp
ON tmp.pcsp_prd=t.pcsp_prd
Go to Top of Page

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-10-03 : 09:49:24
Ok this is working below, but it is also brining over ones that have mulitple addresses. is there a way that I can say something like PCSA_ADDR1<>PCSA_ADDR1?


select * from VW_Double_Pricing
where PCSA_tax1 in (

Select Distinct
PCSA_tax1

From VW_Double_Pricing
where pcsp_prd = 'DGH' --and
--PCSA_ADDR1 <> p.PCSA_ADDR1
group by PCSA_tax1

HAVING COUNT (pcsp_prd) > 1)
order by pcs_lname
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 09:52:45
quote:
Originally posted by werhardt

Ok this is working below, but it is also brining over ones that have mulitple addresses. is there a way that I can say something like PCSA_ADDR1<>PCSA_ADDR1?


select * from VW_Double_Pricing
where PCSA_tax1 in (

Select Distinct
PCSA_tax1

From VW_Double_Pricing
where pcsp_prd = 'DGH' --and
--PCSA_ADDR1 <> p.PCSA_ADDR1
group by PCSA_tax1

HAVING COUNT (pcsp_prd) > 1)
order by pcs_lname



you mean br4ing only ones having duplicate pcsp_prd,address combination? then use below

SELECT taxid
FROM YourTable t
JOIN (SELECT pcsp_prd,address
FROM YourTable
GROUP BY pcsp_prd,address
HAVING COUNT(*) >1)tmp
ON tmp.pcsp_prd=t.pcsp_prd
AND tmp.address=t.address
Go to Top of Page

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-10-03 : 11:45:16
This is starting to look good, but it is still not pulling like i want it to. Maybe it can't be done.
It is pulling both of these for this doctor, maybe I shouldn't use the taxid. Maybe I should use the PCS number that goes to the doctor. I only want it to pull the one in in read because they have the product twice under that doctor.

ALFRED SWYER 1176 5TH AVENUE, BOX 1235
TAX-009010020 NEW YORK, NY 10029
* DAMTS DGH EFF: 11/05/2002 TRM: PHYFEE

MT. SINAI RADIOLOGY ASSOCIATES 1176 FIFTH AVE.
TAX-136171197 NEW YORK, NY 10029-6503
* DAMTS DGH EFF: 10/02/2006 TRM: PHYFEE
* GHINA PPO EFF: 07/01/1996 TRM: GHINAL
* GHINA PPO EFF: 11/06/2003 TRM: GHINAL
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 11:53:19
quote:
Originally posted by werhardt

This is starting to look good, but it is still not pulling like i want it to. Maybe it can't be done.
It is pulling both of these for this doctor, maybe I shouldn't use the taxid. Maybe I should use the PCS number that goes to the doctor. I only want it to pull the one in in read because they have the product twice under that doctor.

ALFRED SWYER 1176 5TH AVENUE, BOX 1235
TAX-009010020 NEW YORK, NY 10029
* DAMTS DGH EFF: 11/05/2002 TRM: PHYFEE

MT. SINAI RADIOLOGY ASSOCIATES 1176 FIFTH AVE.
TAX-136171197 NEW YORK, NY 10029-6503
* DAMTS DGH EFF: 10/02/2006 TRM: PHYFEE
* GHINA PPO EFF: 07/01/1996 TRM: GHINAL
* GHINA PPO EFF: 11/06/2003 TRM: GHINAL



ok. so now what you should do is to give some sample data from your table and then give your expected output out of them.
Go to Top of Page

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2008-10-07 : 10:13:52
Ok, I am still having problems with pulling dups. You said something about giving you some data to test it on. How would I do that? Would I just copy it into this forum?

I think I need to change the way the query is too. It is pulling the DGH, but it is pulling if for every provider. I want to limit it to say If there is a Address (pcsa_addr1) that has (pcsp_prd) "DGH" under it more than once, then I want to see them in my results.


SELECT taxid
FROM YourTable t
JOIN (SELECT pcsp_prd
FROM YourTable
GROUP BY pcsp_prd
HAVING COUNT(*) >1)tmp
ON tmp.pcsp_prd=t.pcsp_prd

Diane Weaver M.D.
Network Product


Devon DGH
Devon DGH


Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-07 : 10:20:13
You can post a simple script.
create temp table (...)
insert some example data

then explain expected output in relation to example data.

Greetings
Webfred

Planning replaces chance by mistake
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-07 : 10:20:48
provide some sample data along with your table column info and show us what your output should be.

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-07 : 10:22:32
Oh, sorry visakh.
I don't wanted to disturb.

Planning replaces chance by mistake
Go to Top of Page
   

- Advertisement -