How to replace null values in a column with "0"

facing problem while trying to replace the null values in a particular column to “0”

Please help me regarding the issue

Thanks in advance

hi
yourstringvariable.ToString.Replace(“”,“0”)

hope this would help you
Cheers @AryanSingh

i am trying to replace all the null values with “0” in a column from the data table.

@Palaniyappan

please check this!!

tried this way but not able to replace the null values!

@Palaniyappan

1 Like

Fine in that case
–hope you have a datatable ready and lets name it outdt
–now use a for each row loop and pass that variable as input
–inside this use a if condition like this
String.IsNullOrEmpty(row(“yourcolumnname”).ToString)
if true goes to THEN part where use a assign activity like this
row(“yourcolumnname”) = “0”

Cheers @AryanSingh

Hi @AryanSingh

You can check whether the string is null using the below command in an IF activity

String.IsNullOrEmpty(YourStringVariable)

This will return true if the variable has a null. Within the Then segment of the IF activity, you can use an assign activity to assign the variable with the default “0”.

You also mentioned that you want to replace null values in a Column. Is this a data table?
Then you can do the following

  • Use a for each row activity to loop through the data table
  • Use the same command above within a IF activity and place it inside the loop. The command will have to be changed to support data table row like

IF String.IsNullOrEmpty(row(“ColumnName”).ToString)

If activity is the same as above :slight_smile:

1 Like

@Palaniyappan
@Lahiru.Fernando

Thanx… Let me try.
Will get back to u!

2 Likes

Sure
Cheers @AryanSingh

@Palaniyappan
@Lahiru.Fernando

Hi i have successfully done the replacement but now facing another issue

Input string was not in correct format.

Please help me with this.

Fine
how would be the value of BaseOutstanding column would be
can we have a sample - screenshot if possible
Cheers @AryanSingh

@Palaniyappan
@Lahiru.Fernando

Please check this. Column values after replacement are like this.

Has both negative and positive values. So need to add all the values.

Is there any necessity to convert them as double
— I hope the variable retvalue is of type Double

Cheers @AryanSingh

@Palaniyappan

as u can see there are decimal values so need to add all the values…thats y i converted them to the double.

1 Like

Please check this. spaces are present between the digits

Due to spaces. So tried using the “trim” command like given below:

But still facing the issue of format not correct

@Palaniyappan

1 Like

Fine
i hope the issue is due to - symbol before value and space between the values
let me check once
Cheers @AryanSingh

ok…so i should replace the “-” sign with the “”

Then subtract the them by using the assign activity, right?

@Palaniyappan

1 Like

yes exactly
Cheers @AryanSingh

ok. let me try.

Will tell u if resolved.

@Palaniyappan

1 Like

Sure
Cheers @AryanSingh

@Palaniyappan

Still facing the same issue when trying to replace the “-” sign

Please check it. Is my command correct?

1 Like