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 |
mkdlmr
Starting Member
21 Posts |
Posted - 2014-01-17 : 16:03:30
|
Hi All,I have a table with organizations. Within that table there are Organization_IDs and Organization_Parent_IDs. These two values should correspond to each-other or the Organization_Parent_IDs value should be null. Can you please tell me how I can go about searching for orphaned organizations?Thanks,Mark |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2014-01-17 : 17:50:42
|
SELECT * FROM <Table>WHERE (Organization_Parent_ID NOT IN (SELECT DISTINCT Organization_ID FROM <table>)) AND Organization_Parent_ID IS NOT NULLHTH,-ChadMicrosoft Certified Master SQL Server 2008 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-18 : 02:21:55
|
quote: Originally posted by mkdlmr Hi All,I have a table with organizations. Within that table there are Organization_IDs and Organization_Parent_IDs. These two values should correspond to each-other or the Organization_Parent_IDs value should be null. Can you please tell me how I can go about searching for orphaned organizations?Thanks,Mark
SELECT *FROM Organizations oWHERE NOT EXISTS (SELECT 1FROM OrganizationsWHERE Organization_IDs = o.Organization_Parent_IDs )AND Organization_Parent_IDs IS NOT NULL ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
mkdlmr
Starting Member
21 Posts |
Posted - 2014-01-21 : 11:03:31
|
Thanks guys! I'm up and working! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-22 : 06:37:31
|
cool------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|