Skip to main content
Answer

Check for data types

  • July 1, 2021
  • 6 replies
  • 604 views

Michaelh
Pro I
Forum|alt.badge.img+2

How do I check for a data type in the generic inquiry screen? 

Like iif( ISNUMBER([FIELD]), True Path, False Path)

I have an Inventory Item Attribute that USUALLY holds an integer value. I wish to do math on this value when it is an integer, but when it is a text string it crashes the report. If I could do some kind of error checking like in Excel, I can force this to work by using IIF to ignore non-integer values.

Best answer by ChandraM

Hi @Michael Hansen  The other logic you can try is to check the first character in the string as shown below.

iif(

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’0’

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’1’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’2’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’3’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’4’,[InventoryItem.EAPACK_Attributes],1) 

** as the Max value is 48, I just added the range till ’4’.Extend it till 9 if required.

Thanks

6 replies

Forum|alt.badge.img+8
  • Semi-Pro I
  • July 1, 2021

Hi @Michael Hansen , Please try using IIF(CSANSWERS.Value>0 and CSANSWERS.Value <10000, true path , falsse path). ** In this case use the expected range of integer values.

 

Thanks 


Michaelh
Pro I
Forum|alt.badge.img+2
  • Author
  • Pro I
  • July 1, 2021

Unfortunately I still get the error on exporting.

Error:

 

Time 00:05; Conversion failed when converting the nvarchar value 'HG-6/TJX-4' to data type int.

 

My Code is (there’s more surrounding it, but it seemed obfuscating to the topic):

=iif([InventoryItem.EAPACK_Attributes]>0 AND [InventoryItem.EAPACK_Attributes]<1000,

[InventoryItem.EAPACK_Attributes],1)

My Values are pack sizes for goods, so 48 is pretty much my top end integer value.


Forum|alt.badge.img+8
  • Semi-Pro I
  • Answer
  • July 1, 2021

Hi @Michael Hansen  The other logic you can try is to check the first character in the string as shown below.

iif(

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’0’

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’1’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’2’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’3’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’4’,[InventoryItem.EAPACK_Attributes],1) 

** as the Max value is 48, I just added the range till ’4’.Extend it till 9 if required.

Thanks


Forum|alt.badge.img+8
  • Semi-Pro I
  • July 1, 2021

Hi @Michael Hansen  The other logic you can try is to check the first character in the string as shown below.

iif(

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’0’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’1’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’2’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’3’ or

Left(LTrim([InventoryItem.EAPACK_Attributes]),1) =’4’,[InventoryItem.EAPACK_Attributes],1) 

** as the Max value is 48, I just added the range till ’4’.Extend it till 9 if required.

Thanks


Michaelh
Pro I
Forum|alt.badge.img+2
  • Author
  • Pro I
  • July 1, 2021

That is cheating! I love it. Sure it’s a bit unwieldy, but until we get formal type checking, this is awesome-sauce. Thank you so much!


Forum|alt.badge.img+8
  • Semi-Pro I
  • July 1, 2021

Hi @Michael Hansen Good to know that the solution worked.

Thanks