Jump to content
  • 0

Get the difference of two strings converted to int


crionsynx

Question

image.png.ae2f16262d05eb8cac0be9e2da5973d3.png

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

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.

image.png.ea65bed2d10b38aaa6447c8a4878fb5d.png

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.

image.png.80e153b1afcd30b7b077ad3c63054877.png

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:

CASE
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'
END


image.png.4556da39e8c9fe9b2e0f2470beaf81b3.png

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.

Guest
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.

Loading...
×
×
  • Create New...