Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Convert String to Integer datatype

tejashriw155148
Level 4
Level 4

Hi,

 

Please let me know how can I convert string data to integer datatype.

 

Thanks,

1 Accepted Solution
Milan_Vucetic
Correct answer by
Community Advisor
Community Advisor

Hi @tejashriw155148 ,

 

you must do a split after query selection to get two branches (one for INT and another for STRING).

After that you may convert to  preferred type in Enrichment nodes in needed (per branch.)

 

If your data have only two characters you may adapt query in split:

  1. To identify numbers something like: first character in (1,2,3,4,5,6,7,8,9) and second character in (1,2,3,4,5,6,7,8,9)
  2. To identify non-numbers just enable Complement of point 1 to get all non-numbers

 

Generally, with provided data all input values are string. Then you need to separate it with split (above) and do conversion of numbers to integer.

 

Regards,

Milan

View solution in original post

7 Replies
Manoj_Kumar_
Community Advisor
Community Advisor

Hello @tejashriw155148 

 

You can try ToInt64(<number>) or ToInteger(<number>) depending on your use case.

Thanks,
Manoj

tejashriw155148
Level 4
Level 4

Hello @Manoj_Kumar_ , 

 

I tried ToInt64(<number>) but its showing Error converting datatype varchar to bigint

and for ToInteger(<number>) Conversion failed while converting the varchar value 'LG' to data type int

 

Do you have any other solution?

 

Thanks.

 

 

tejashriw155148
Level 4
Level 4

Hi @Manoj_Kumar_ 

 

I have code field with string data type and data as below:

02

98

LG

Tr

09

 

I want to compare only integer data with other field which contain integer data.

 

Thanks,

 

Darren_Bowers
Community Advisor
Community Advisor

Looking at your data below, you cant convert an alpha-based string to an integer. It has to be a numeric string only.

Hard to know what your actual data looks like with that small sample, but if you can assume that the non-numeric data will always start with an alpha character, you can do something like this:

Iif(Ascii(Left(@yourColumn,1)) < 58 and Ascii(Left(@yourColumn,1)) > 47, ToInteger(@yourColumn) , -1 )

This checks the first character to see if it is between 0 and 9. If it is then convert the value to an Integer. Otherwise put "-1" in the data.

 

Milan_Vucetic
Correct answer by
Community Advisor
Community Advisor

Hi @tejashriw155148 ,

 

you must do a split after query selection to get two branches (one for INT and another for STRING).

After that you may convert to  preferred type in Enrichment nodes in needed (per branch.)

 

If your data have only two characters you may adapt query in split:

  1. To identify numbers something like: first character in (1,2,3,4,5,6,7,8,9) and second character in (1,2,3,4,5,6,7,8,9)
  2. To identify non-numbers just enable Complement of point 1 to get all non-numbers

 

Generally, with provided data all input values are string. Then you need to separate it with split (above) and do conversion of numbers to integer.

 

Regards,

Milan

View solution in original post