views:

55

answers:

2

I was just trying this knowing that my select would return one row. Is something like this possible or will I need a temporary variable?

lets say my stored procedure took one parameter:

exec dbo.GetUserData @UserName = UserName from @MyTempTable where UserId= @UserId

Or what if the parameter expected was XML? Is there a way I can do something like

exec dbo.GetUserData @UserXml =
    select 
        case 
         when @val = 1 then '1' 
         when @val = 0 then '0' 
         else NULL 
        end as '@MyId',
        @ThisId as '@ThisId',
        @ThatId as '@ThatId'
    FOR XML PATH('Info')
+3  A: 

XML or otherwise, assign the value to the variable before using the variable in the EXEC call.

DECLARE @UserName [data type]

BEGIN

  SELECT @UserName = UserName 
    FROM @MyTempTable 
   WHERE UserId = @UserId

    EXEC dbo.GetUserData @UserName

END
OMG Ponies
Or what OMG Ponies said :)
rob_g
how do i put the results of a for xml into a temp variable?
towps
+3  A: 

You'll need a temporary variable.

DECLARE @username nvarchar(20) 
SELECT @username = Username FROM @MyTempTable WHERE UserId=@UserId

exec dbo.GetUserData @Username.
rob_g
yeah i figured as much. in my situation it'd be a lot quicker if i didn't have to create temp variables for all my params so i though there might be a way to just do a select similar to how i presented it.
towps