Jump to content
  • 0

Get the difference of two strings converted to int




WHEN Charindex('-',[@field:BoxNumber],0) >= 1 THEN
(Cast((Right([@field:BoxNumber], (Len([@field:BoxNumber])-Charindex('-', [@field:BoxNumber])))) AS int))
(Cast((Left([@field:BoxNumber], Charindex('-', [@field:BoxNumber])-1)) AS int))
) AS varchar)

I have the above code inserted in [BoxCount] formula datatype field to get the difference of two values from a single field ([BoxNumber]) if it has dash(-) in it else it should be set to one(1). 

Below is an example. For the highlighted row, the result of the formula should be 2 - basically (35142-35141)+1.


When I checked it in the "Verify formula" button, caspio considered it as valid but when I tried saving it, caspio throws the below error.


What am I missing here?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

I also tried to run you formula and its not working properly. I created my own version:

WHEN Charindex('-',[@field:BoxNumber]) > 0
THEN CONVERT(INT,Left([@field:BoxNumber], Charindex('-',[@field:BoxNumber])-1)) - CONVERT(INT,right([@field:BoxNumber], (Len([@field:BoxNumber]) -Charindex('-',[@field:BoxNumber])))) +1
ELSE '1'


Link to comment
Share on other sites

  • 0

Thank you for looking into this @Wikiwi.

I think my formula is also working and I found out now the real issue. It is not because of the formula but because of the existing data in the BoxNumber field.

I have some data in the BoxNumber field that have string(alphabet) values besides the dash(-) itself.

It will fail since it is impossible to convert.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...