none
Assign result column value to a variable

    Question

  • Using U-SQL, after retrieving a result with 1 row and 1 column, how can I assign the 1 column value to a variable to be used in later WHERE clauses or calculations. Does this result always need to be joined to in order to use the value?

    @configPercentage = SELECT  Value
            FROM    @myconfiguration
            WHERE   Key == "configpercentage";  //returns 1 row 1 column

    @Resut2= SELECT  Value * @configPercentage.Value   //want to use it here as a variable
            FROM    @datafile


    Friday, December 18, 2015 3:59 PM

Answers

  • Hi Wayne,

    U-SQL doesn't support converting a single column, single row table into a scalar value at the present time.

    It's likely that you've figured this out by now but you could simply CROSS JOIN the @datafile expression with the @configPercentage expression to make the value accessible in the @Result2 expression.

    @Result2= 
      SELECT @datafile.Value * @configPercentage.Value AS DerivedValue
      FROM @datafile
        CROSS JOIN @configPercentage


    Regards,

    Michael Amadi

    Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)

    Website: http://www.nimblelearn.com, Twitter: @nimblelearn

    Thursday, April 7, 2016 11:22 AM