You are here: Re: cursor to compare/report on the same fields in 2 tables « MsSQL Server « IT news, forums, messages
Re: cursor to compare/report on the same fields in 2 tables

Posted by Ed Murphy on 09/21/06 01:52

SQLNewbie wrote:

> I have the following cursor that I am comparing 2 tables, the
> production table and a copy of the production table, I want results of
> all address's that are like the address1 field...the problem is...my
> results are giving me every field and if there is more than one, it is
> putting it in a grid....
>
> I only want to see results if they are > 1 for the same address field
>
> this is what I have so far....
>
>
> declare @address1 char(61),@city char(61)
>
> declare address_cursor CURSOR FOR
> SELECT address1,city FROM test.dbo.testadd
>
> OPEN address_cursor
>
> fetch next from address_cursor into @address1,@city
> while @@fetch_status = 0
> BEGIN
> select * from testadd where @address1 like '%' + address1 + '%' and
> @city = city
> Fetch next from address_cursor into @address1,@city
> Print
> END
> CLOSE address_cursor
> DEallocate address_cursor

See if this points you in the right direction:

select t.address1, t.city, count(*)
from test.dbo.testadd t
join production.dbo.testadd p on t.city = p.city
where p.address1 like '%' + t.address1 + '%'
group by t.address1, t.city
having count(*) > 1

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация