Search code examples
type-conversionu-sql

U-SQL DataType conversion


I am having a column in my sample data which contains 1 or 0 or "null". Due to "null" string I have declared the type of the column as string. In next operation I am taking only 1 & 0 and doing SUM(Value) where I am getting error cannot convert from "string" to "long?"


Solution

  • To another approach to this problem you can do something like this. I'm suggesting the column name as "amount":

    @input= SELECT CASE column WHEN amount THEN "0" ELSE amount END AS Amount FROM @extractedFields

    @sum= SELECT SUM(Int32.Parse(Amount)) FROM @input

    By this approach the input to the sum will only have in consideration the elements with 1 and 0.