This is my first post on this forum and I am very new to TSQL. I do have some database experience, as I have created/modified SQL and PLSQL in Oracle. I am currently looking into debugging a SQL Server stored procedure that someone else wrote and I am confused. Here is the code paraphrased a bit:
CREATE PROCEDURE [dbo].[sp_MySP]
@p1 int OUTPUT,
@p2 int OUTPUT
SELECT @p1 = count(*)
FROM <some table>
SELECT @p2 = count(*)
FROM <same table>
I think I understand what the above SP is doing for the most part. It has 2 output parameters and it assigns them the result of counts on the table. Then these 2 paraemters(with the count values) are returned back to the calling program. When I go to comple this code, I get an error saying something to the effect that you can't do an assignment before and after a UNION. So, I looked this up and was in the process of rewriting this with the UNION ALL, but in a different way to get over this error.
Then I started to looking into what is it actually doing and the UNION ALL being used here baffles me. I understand what a UNION ALL does, but how is it applicable here? It makes no sense why you would want to union 2 assignments together? Do you know what is going on with that? I was thinking I was just going to remove the UNION. Will I get the same results? Thanks.