Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: T-SQL Dupli...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 10955 of 11431
Post > Topic >>

Re: T-SQL Duplicate Record Help

by Tom van Stiphout <no.spam.tom7744@[EMAIL PROTECTED] > Apr 12, 2008 at 05:59 PM

On Sat, 12 Apr 2008 20:55:04 +0100, "Jane T" <janet@[EMAIL PROTECTED]
> wrote:

(I renamed your table to tblTest)
Here is how I solve it for simple cases involving a single field:
select reference_
  from tblTest
  group by reference_
  having count(reference_) > 1

With more than one field, I simply concatenate those fields and then
I'm using the same method as in the first query:
select reference_ + '-' + cast(value_ as varchar)
	from tblTest
	group by reference_ + '-' + cast(value_ as varchar)
	having count(reference_ + '-' + cast(value_ as varchar)) > 1

If you then want the entire records for the found values, then compare
the concatenated values with those of the values from the previous
query:
select * 
	from tblTest
	where reference_ + '-' + cast(value_ as varchar) = (select
reference_ + '-' + cast(value_ as varchar)
	from tblTest
	group by reference_ + '-' + cast(value_ as varchar)
	having count(reference_ + '-' + cast(value_ as varchar)) > 1)

-Tom.


>I want to check the data from an invoicing database for possible
duplicate 
>invoices.
>
>I have created an example script below.
>
>I want to return rows where there is a match for both reference_ and
value_, 
>so in this
>example in my SELECT statement I only want to return the two rows that
match 
>on both
>reference_ and value_
>
>
>CREATE TABLE #TMP
>(reference_ varchar(10), suppliercode_ varchar(10), value_ money)
>
>INSERT INTO #TMP VALUES ('A1','123',100)
>INSERT INTO #TMP VALUES ('A2','234',100)
>INSERT INTO #TMP VALUES ('A1','345',100)
>INSERT INTO #TMP VALUES ('A2','234',70)
>
>SELECT * FROM #TMP ORDER BY REFERENCE_ 
>
 




 4 Posts in Topic:
T-SQL Duplicate Record Help
"Jane T" <ja  2008-04-12 20:55:04 
Re: T-SQL Duplicate Record Help
Tom van Stiphout <no.s  2008-04-12 17:59:37 
Re: T-SQL Duplicate Record Help
Erland Sommarskog <esq  2008-04-13 01:59:02 
Re: T-SQL Duplicate Record Help
"Plamen Ratchev"  2008-04-12 23:29:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 13:29:12 CDT 2008.