Question : Need help joining 2 queries.

I have a function from an MS Acess 2003 database from end linked to SQL Server 2000 backend.  The attached function creates two queries with the required parameters than a third query joins the previous two and returns a recordset.  

This works perfectly fine, but now I need to get the same end result (data) into an ASP.NET web page and I'm not sure how to approach it.  I'd love to get the three queries into a single SQL statement, but if it's even possible, I'm not slick enough to do it.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
Private Function TemplateComparison(WorkFlowTemplate As Integer) As DAO.Recordset
On Error GoTo ErrorHandle
       
       Dim qry1SQL As String
        qry1SQL = "SELECT tblWorkFlowTemplates.MasterProcessID, tblWorkFlowAssignmentsDetail.WorkFlowAssignmentID, tblWorkFlowTemplates.ProcessSequence," & _
                " tblWorkFlowTemplates.TemplateMasterID, tblWorkFlowAssignmentsDetail.Completed" & _
                " FROM tblWorkFlowAssignmentsDetail INNER JOIN tblWorkFlowTemplates ON" & _
                " tblWorkFlowAssignmentsDetail.WorkFlowProcessID = tblWorkFlowTemplates.WorkFlowProcessID" & _
                " WHERE tblWorkFlowAssignmentsDetail.WorkFlowAssignmentID = " & mWorkFlowAssignmentID & _
                " ORDER BY tblWorkFlowTemplates.ProcessSequence;"

        Dim qry1 As QueryDef
        Set qry1 = CurrentDb.CreateQueryDef("CurrentTemplate", qry1SQL)

        Dim qry2SQL As String
        qry2SQL = "SELECT tblWorkFlowTemplates.MasterProcessID, tblWorkFlowTemplates.ProcessSequence," & _
                " tblWorkFlowTemplates.TemplateMasterID, tblWorkFlowTemplates.WorkFlowProcessID" & _
                " From tblWorkFlowTemplates" & _
                " WHERE tblWorkFlowTemplates.TemplateMasterID = " & WorkFlowTemplate & _
                " ORDER BY tblWorkFlowTemplates.ProcessSequence;"
        Set qry2 = CurrentDb.CreateQueryDef("NewTemplate", qry2SQL)

        Dim templateSQL As String
        templateSQL = "SELECT NewTemplate.ProcessSequence, NewTemplate.MasterProcessID, NewTemplate.WorkFlowProcessID" & _
            " FROM CurrentTemplate RIGHT JOIN NewTemplate ON CurrentTemplate.MasterProcessID =" & _
            " NewTemplate.MasterProcessID" & _
            " WHERE (((CurrentTemplate.MasterProcessID) Is Null)" & _
            " OR ((CurrentTemplate.Completed) = False))" & _
            " ORDER BY NewTemplate.ProcessSequence"

        
        Dim rst As DAO.Recordset
        Set rst = CurrentDb.OpenRecordset(templateSQL)
        Set TemplateComparison = rst
        Set rst = Nothing

        CurrentDb.QueryDefs.Delete qry1.Name
        CurrentDb.QueryDefs.Delete qry2.Name
        
ExitHandle:
    Exit Function

ErrorHandle:
    MsgBox Err.Description
    DoCmd.SetWarnings (True)
    Resume ExitHandle
    
End Function

Answer : Need help joining 2 queries.

You will notice two @'s in there. These are for you to parameterize.  Alternatively, you can always append to the string into those two places.
I take it tblWorkFlowAssignmentsDetail.Completed is a bit field, so as a normal T-sql query, it should be tested against 0 not False.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
SELECT NewTemplate.ProcessSequence, NewTemplate.MasterProcessID, NewTemplate.WorkFlowProcessID
FROM (
	SELECT tblWorkFlowTemplates.MasterProcessID, tblWorkFlowAssignmentsDetail.WorkFlowAssignmentID, tblWorkFlowTemplates.ProcessSequence,
	tblWorkFlowTemplates.TemplateMasterID, tblWorkFlowAssignmentsDetail.Completed
	FROM tblWorkFlowAssignmentsDetail INNER JOIN tblWorkFlowTemplates ON
	tblWorkFlowAssignmentsDetail.WorkFlowProcessID = tblWorkFlowTemplates.WorkFlowProcessID
	WHERE tblWorkFlowAssignmentsDetail.WorkFlowAssignmentID = @mWorkFlowAssignmentID
	ORDER BY tblWorkFlowTemplates.ProcessSequence
	) CurrentTemplate
RIGHT JOIN (
	SELECT tblWorkFlowTemplates.MasterProcessID, tblWorkFlowTemplates.ProcessSequence,
	tblWorkFlowTemplates.TemplateMasterID, tblWorkFlowTemplates.WorkFlowProcessID
	From tblWorkFlowTemplates
	WHERE tblWorkFlowTemplates.TemplateMasterID = @WorkFlowTemplate
	ORDER BY tblWorkFlowTemplates.ProcessSequence
	) NewTemplate ON CurrentTemplate.MasterProcessID = NewTemplate.MasterProcessID
WHERE CurrentTemplate.MasterProcessID Is Null OR CurrentTemplate.Completed = 0
ORDER BY NewTemplate.ProcessSequence
Random Solutions  
 
programming4us programming4us