Reputation: 440
I'm trying to produce a Winforms report in my .NET application. Our users want to know for a specific welder what type of welds they have done between two dates. The users also need proof that this weld has been completed. The front end is straightforward but I'm struggling on how to get the data.
I have the following SQL query in a stored procedure:
INPUT parameters: @WelderNo INT, @StartDate DATETIME, @EndDate DATETIME
SELECT DISTINCT wi.wi_wpsnumbers
FROM wi_weld_instance wi
INNER JOIN wlds_weld_section ws ON wi.weldinstanceid = ws.weldinstanceid
INNER JOIN erd_employee_resourcedetails e ON e.employeeid = ws.employeeid
WHERE (wi.wi_completiondate Between @StartDate AND @EndDate)
AND e.erd_welderno in (@WelderNo)
Now I want to get some other information on each distinct wi_wpsnumbers that was returned. This is the proof that the weld has been completed. The query would look something like this:
Input parameters: @WelderNo INT, @StartDate DATETIME, @EndDate DATETIME, @wi_wpsnumber NVARCHAR(MAX)
SELECT TOP(1) e.fabemployeename,
erd_welderno,
(pm.PM_Number),
(mm.mm_assemblymark),
(wd.wd_number),
(wd.wd_length),
(wi.wi_completiondate)
FROM wi_weld_instance wi
INNER JOIN wlds_weld_section ws ON wi.weldinstanceid = ws.weldinstanceid
INNER JOIN erd_employee_resourcedetails e ON e.employeeid = ws.employeeid
INNER JOIN wd_weld_definition wd ON wd.welddefinitionid = wi.welddefinitionid
INNER JOIN pm_project_map pm ON pm.projectmapid = wd.projectid
INNER JOIN mm_mark_map mm ON wd.assemblyid = mm.markmapid
WHERE (wi.wi_completiondate Between @StartDate AND @EndDate)
AND e.erd_welderno in (@WelderNo) AND wi.wi_wpsnumbers = @wi_wpsnumber
How can I create a stored procedure that returns a table with the combination of both these queries? I can't combine the queries as the distinct will not work and return multiple wi_wpsnumbers the same. I was looking at temp tables but then I don't understand how to insert both the results of these queries into the same row. Thanks for your help
Link to database diagram: http://i1215.photobucket.com/albums/cc510/gazamatazzer/DatabaseDiagram.jpg
Upvotes: 0
Views: 2500
Reputation: 10349
You can return two resultsets from an SP.
Just call two SELECTs and use NextResult in the client code to retrieve the second resultset after you have read the first one.
Upvotes: 3
Reputation: 4259
select x.*, y.* from
(select * from xtable) x, (select * from ytable) y
Where x.*
gives you all from xtable
and y.*
gives all from ytable
Upvotes: 0