none
How to get values from a 2nd result set RRS feed

  • Question

  • All, I have a query that returns 2 result sets as shown in the screen shot.  My problem is I want to get the value in the first column of the 2nd result set, but I'm afraid I don't know how to do that.  Any help would be appreciated:


    Tim

    DECLARE @maj int=7,
    @min int=4,
    @maint int=0,
    @b int=300,
    @r char(1)
    
    SELECT top 1 major,minor,Maintenance,build
    FROM Maintenance.DatabaseVersion
    WHERE EXISTS
        (SELECT top 1 Major,Minor,Maintenance,Build 
         FROM Maintenance.DatabaseVersion
         WHERE major = @maj
    	 AND minor = @min
    	 AND Maintenance = @maint
    	 AND Build = @b
         ORDER BY DatabaseVersionID DESC
    	 );
    	If @@ROWCOUNT = 0 
    		begin
    			set @r = 'N'
    		End
    		else
    		begin
    			set @r = 'Y'
    		end
    SELECT @r as UPD
    


    Friday, October 18, 2019 8:35 PM

All replies

  • Where do you want to get this value? The context is not clear.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    Friday, October 18, 2019 9:07 PM
  • Hi Erland, I want to get the value in the 2nd result set with (no column name).  Hope this helps!

    Tim

    Friday, October 18, 2019 9:10 PM
  • Hi Erland, I want to get the value in the 2nd result set with (no column name).  Hope this helps!

    Want to get the value where? As far I can tell from the screenshot you already have the value right in from you. So you seem to be asking for more. But since I canont read your mind, I don't know what more you are asking for.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    Friday, October 18, 2019 9:30 PM
  • Hi TimStspry,

    >> I want to get the value in the 2nd result set with (no column name).  Hope this helps!

    According to  your screenshot,  it seems you have achieve your goal. If I misunderstood your issue, please let me know. And describe your issue more clearly.

    Best regards,
    Cathy 

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to  MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Monday, October 21, 2019 5:52 AM
  • Thanks Cathy.  I appreciate your answer.  What I am trying to do is get the value in the 2nd result set in the column (No Column Name).  In the screen shot the value is 1.

    Tim

    Monday, October 21, 2019 1:49 PM
  • Not sure how you got the second result listed on your screenshot. The second one should be the value of either N or Y with column name UPD.

    A Fan of SSIS, SSRS and SSAS

    Monday, October 21, 2019 2:51 PM
  • Do you mean how to get the second result programmatically? Then give some details about your program, language.

    Monday, October 21, 2019 3:15 PM