Sending Blank 'Decimal'-typed Values to SQL

Hey guys I’ve been having this issue in sendign a blank variable to a decimal value into SQL without UiPath drawing an error. (I haven’t written out the full, or completely correct version of the code here just enough that you can see how I’m setting up the variable in question)

“Update Set [Value_1] = '”+vMyDecimalValue+"’, [Value_2] = ‘"+vMySecondVariable+"’, [Value_3] = ‘"+vMyThirdVariable+"’"

I have it basically setup as the above which will work when the value I’m putting into SQL is not blank (so for example 43.28) but if vMyDecimalValue="" then it draws a conversion error. I’ve also tried using this in the update statement:

"Update Set [Value_1] = ‘+vMyDecimalValue+’ " – and then basically added the extra quotes in an if statement if vMyDecimalValue is not equal to “”

Any help on this?

Hi @css,

It may be getting an error because the field you’re inserting the blank (’’) value is expecting a number/decimal. Can you try sending 0 or 0.00 instead of blank?

Yea so as long as the value is a number (0 or 0.00 would be a good case) I have no issues. But sometimes with the bot its going to grab out a “” value. So in those cases I need to somehow keep the same SQL statement but have that blank or ‘NULL’ value go through.

I am currently trying replacing the variable in UiPath with a Nullable variable to see if that works – but again I just don’t know what the proper way to work with this situation would be.

Hi @css,

Maybe you can try checking if the bot grabbed a ‘’ value.

String.IsNullOrEmpty(variableName)

If it does, then replace the ‘’ variable value with 0. I don’t think SQL allows null value to be entered for numeric data types. :slight_smile:

Did you try changing the value with IIf?

String.Format("Update Set [Value_1]={0}, [Value_2]='{1}', [Value_3]='{2}'", IIf(isNothing(vMyDecimalValue), "NULL", vMyDecimalValue), vMySecondVariable, vMyThirdVariable)

or if the ' around the value for Value_1 are expected:

String.Format("Update Set [Value_1]={0}, [Value_2]='{1}', [Value_3]='{2}'", IIf(isNothing(vMyDecimalValue), "NULL", "'" & vMyDecimalValue & "'"), vMySecondVariable, vMyThirdVariable)