You are here: Re: Merging two tables with selection « MsSQL Server « IT news, forums, messages
Re: Merging two tables with selection

Posted by Erland Sommarskog on 08/26/06 20:57

Bruce Stradling (bstradling@cox.net) writes:
> I would like to Merge these two tables using the following logic.
> The SystemPropertyTypeTable any records that have "ACTIVE" for the status.
> The UserPropertyTypeTable all records.
>
> Group by Name and remove any duplicates. if the UserPropertyTypeTable
> has INACTIVE then Throw away the Active Record from the
> SystemPropertyTypeTable and keep the INACTIVE record.

If I understand this correctly, you want:

SELECT U.PropertyType, U.Description, U.Status
FROM UserPropertyTable U
UNION ALL
SELECT S.PropertyType, S.Description, S.Status
FROM SystemPropertyType S
WHERE S.Status = 'ACTIVE'
AND NOT EXISTS (SELECT *
FROM UserPropertyTable U
WHERE S.Property = U.Property)


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

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

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