Hi, all. Hope you can assist with another of my confusing SQL statements.
I have a list of questions for a particular package. For package there are 2 (possible more in future) processes, and for each process I need to mark whether or not that quality assurance check has been performed. So my front end looks like this:
PackageID = 53
QA Check.............Process1...............Process2
Check 1...............[checkbox]............[checkbox]
Check2................[checkbox]............[checkbox]
At the back-end, I have 4 tables:
Process - list of processes for each package
ProcessID........Process Name
1....................Process1
2....................Process2
Package - list of packages
PackageID......Package Name
1...................Package1
2...................Package2
QAChecks - list of QA checks
QACheckID......QACheckQuestion
1...................Check1
2...................Check2
PackageQAChecks - the results of the QA check per package/process
PackageQACheckID.......PackageID.....ProcessID......QACheckID......Checked
1.......1.......1........1........1
2.......1.......2........1........0
My SQL statement is this:
Code:
SELECT [qaChecks].qaCheckID,[qaChecks].qaCheckQuestion
,(CASE WHEN [packageQAChecks].[ProcessID] = 1 Then [checked]
WHEN [packageQAChecks].[ProcessID] IS NULL Then 0
END) As Process1,
(CASE WHEN [packageQAChecks].[ProcessID] = 2 Then [checked]
WHEN [packageQAChecks].[ProcessID] IS NULL Then 0 END) As Process2
FROM [ApplicationTracking].[dbo].[qaChecks]
LEFT JOIN [ApplicationTracking].[dbo].[packageQAChecks]
ON [packageQAChecks].[qaCheckID] = [qaChecks].[qaCheckID]
The reason I use the LEFT JOIN is because if the checks havent been filled out yet, I still need the questions to display with checkboxes.
Anyway, the results I get is this:
qaCheckID.....qaCheckQuestion....Process1.....Process2
1..................Check1..................1................NULL
1..................Check1...................NULL.........0
But I want:
qaCheckID.....qaCheckQuestion....Process1.....Process2
1..................Check1..................1................0
How can I change my SQL statement to get this result?
Thanks....