I am working on a SQL statement the works on relationships mapped amongst software and hardware.
The result I am looking for from the following statement should look like this: (the example table is in code style for formatting purposes)
The result should contain all
Environment -> Server -> App
relationships in the table and if the server has a DR Server associated with it it should be list
In the SQL statement below the first select grabs all the Servers with a DR Server mapped to it and the second select grabs the rest of the relationships without a DR Server mapped to it. Here is my code:
Can anyone help me with a similar example whether it is original or can be viewed on a site?
The result I am looking for from the following statement should look like this: (the example table is in code style for formatting purposes)
Code:
----------------------------------------------- | App Name | Server | Environment | DR Server | ----------------------------------------------- | App1 | svr1 | Env1 | svr3 | | App1 | svr2 | Env2 | | . . .
Environment -> Server -> App
relationships in the table and if the server has a DR Server associated with it it should be list
In the SQL statement below the first select grabs all the Servers with a DR Server mapped to it and the second select grabs the rest of the relationships without a DR Server mapped to it. Here is my code:
Code:
select a.[ApplicationName] as [App], a.[RelationshipValue1] as [Server], a.[RelationshipValue2] as [Environment], c.[RelationshipValue1] as [DR Server] from Relationship_Table a, Relationship_Table b, Relationship_Table c where (a.[ApplicationName] = 'ACE' and b.[ApplicationName] = 'ACE' and c.[ApplicationName] = 'ACE') and (a.[RelationshipType] = 'Environment --> Server' and b.[RelationshipType] = 'Environment --> Server' and c.[RelationshipType] = 'DR Server --> Production Server') and (a.[RelationshipValue2] != 'DR' and b.[RelationshipValue2] = 'DR') and (b.[RelationshipValue1] = c.[RelationshipValue1] and a.[RelationshipValue1] = c.[RelationshipValue2]) and (a.[IsDeleted] = 'N' and b.[IsDeleted] = 'N' and c.[IsDeleted] = 'N') UNION select d.[ApplicationName] as [App], d.[] as [Server], d.[RelationshipValue2] as [Environment] from Relationship_Table d where d.[ApplicationName] = 'ACE' and d.[RelationshipType] = 'Environment --> Server' and d.[IsDeleted] = 'N'