locked
Select within Stored Procedure RRS feed

  • Question

  • Hi...

    What the correct syntax for this, im  doing this in a stored procedure.

    	select @useridHigh, @userBalHigh = UserID,MAX(Balance)
    		from [User]
    		where LastName = 'Tom'
    		group by UserID

     Thanks

    Rebekah

    Thursday, May 19, 2011 9:14 AM

Answers

  • Pls try this

    Declare @useridHigh int,@userBalHigh int

    select @useridHigh = UserID, @userBalHigh = MAX(Balance)
            from [User]
            where LastName = 'Tom'
            group by UserID
           
    SELECT @useridHigh, @userBalHigh

     


    http://uk.linkedin.com/in/ramjaddu
    • Proposed as answer by Naomi N Thursday, May 19, 2011 9:34 PM
    • Marked as answer by Stephanie Lv Friday, May 27, 2011 8:48 AM
    Thursday, May 19, 2011 12:55 PM

All replies

  • A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.-

    You need to do this:

     

    select @userBalHigh = UserID,MAX(Balance)
    		from [User]
    		where LastName = 'Tom'
    		group by UserID
    
    SELECT @useridHigh, @userBalHigh

     


    Jeff Wharton MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt) MCT, MCPD, MCITP, MCDBA, MCSD, MCAD
    Thursday, May 19, 2011 9:21 AM
  • Pls try this

    Declare @useridHigh int,@userBalHigh int

    select @useridHigh = UserID, @userBalHigh = MAX(Balance)
            from [User]
            where LastName = 'Tom'
            group by UserID
           
    SELECT @useridHigh, @userBalHigh

     


    http://uk.linkedin.com/in/ramjaddu
    • Proposed as answer by Naomi N Thursday, May 19, 2011 9:34 PM
    • Marked as answer by Stephanie Lv Friday, May 27, 2011 8:48 AM
    Thursday, May 19, 2011 12:55 PM
  • Declare @useridHigh varchar(100),@userBalHigh varchar(100)
    select @useridHigh=UserID, @userBalHigh = MAX(Balance)
    		from [User]
    		where LastName = 'Tom'
    		group by UserID
    

    If this answer is helpful to you .. Please mark as Answer....
    Thursday, May 19, 2011 9:04 PM