Is it possible to perform a dynamic SQL join?

How to self join this SQL?

  • I have one table in my Database that has column names: **buildNumber**, **result**, **versionStatus**. Now in my SQL statement I want to display the 'buildNumber' where the 'versionStatus' is **old** and the 'result' is **pass** and where the versionStatus is **new** and the result is **'fail**'. So I want to display anything that has a result of fail today but had a result of pass last time. So if I have these records in the DB (column separated by --): build2--pass--old build2--fail--new The SQL statement should only display "build2" because it passed with "old" but now 'failed' with new version. I have tried: select * from CSAResults.dbo.Details where result = 'pass' and versionStatus = 'Old' and versionStatus IN (select CSAResults.dbo.Details.versionStatus from CSAResults.dbo.Details where versionStatus = 'New' and result = 'fail') but nothing is returned. Thanks

  • Answer:

    select * from CSAResults.dbo.Details where result = 'pass' and versionStatus = 'Old' and buildNumber in (select buildNumber from Details where VersionStatus = 'New' and result = 'Fail')

adamskii... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

select * from CSAResults.dbo.Details a INNER JOIN CSAResults.dbo.Details b ON a.buildNumber=b.buildNumber AND a.result = 'pass' AND versionStatus = 'Old' AND b.result = 'fail' AND versionStatus = 'New'

SELECT o.buildNumber FROM someTable o, someTable n WHERE o.buildNumber = n.buildNumber AND o.versionStatus = "old" AND n.versionStatus = "new" AND o.result = "pass" AND n.result = "fail"

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.