How to CAST attribute of String type to Integer in OQL?

0
Hi all, I want to know how to cast a attribute of String type to Decimal or Integer Type in OQL query. I have written a query as below: SELECT Name FROM ClassificationUser.ClassInstance Where ClassificationUser.ClassInstance/ClassificationUser.ClassInstance_PartClass/ClassificationAdmin.PartClass/Name = 'Eye Nut'  AND ClassificationUser.ClassInstance/Name = '130512-6'  AND ClassificationUser.ClassInstance/ClassificationUser.AttributeInstance_ClassInstance/ClassificationUser.AttributeInstance/ClassificationUser.AttributeInstance_Attribute/ClassificationAdmin.Attribute/ShortName = 'Thread Size'  AND CAST(ClassificationUser.ClassInstance/ClassificationUser.AttributeInstance_ClassInstance/ClassificationUser.AttributeInstance/AttributeValue  AS INTEGER) = 11 In the highlighted text AttributeValue  is a string which I want to convert to Integer and Search. But when I try it it results in following error; Please help me to solve this error.  
asked
2 answers
0

rewrite to

 

FROM ClassificationUser.ClassInstance CI
INNER JOIN CI/ClassificationUser.ClassInstance/ClassificationUser.ClassInstance_PartClass/ClassificationAdmin.PartClass PC
INNER JOIN CI/ClassificationUser.ClassInstance/ClassificationUser.AttributeInstance_ClassInstance/ClassificationUser.AttributeInstance AI
INNER JOIN AI/ClassificationUser.AttributeInstance_Attribute/ClassificationAdmin.Attribute ATR

WHERE
AI/AttributeValue is not NULL AND
CAST(AI/AttributeValue  AS INTEGER) = 11 AND
PC/Name = 'Eye Nut' AND
CI/Name = '130512-6'  AND
ATR/ShortName = 'Thread Size' 

SELECT Name 

It is recommended to include all the joins in the from part so the where part is much easier

 

you can also use AttributeValue = ‘11’

answered
0

SELECT * FROM ClassificationUser.ClassInstance CI
INNER JOIN CI/ClassificationUser.ClassInstance_PartClass/ClassificationAdmin.PartClass PC
INNER JOIN CI/ClassificationUser.AttributeInstance_ClassInstance/ClassificationUser.AttributeInstance AI
INNER JOIN AI/ClassificationUser.AttributeInstance_Attribute/ClassificationAdmin.Attribute ATR
WHERE
AI/AttributeValue is not NULL AND
PC/Name = 'Eye Nut' AND
CI/Name = '130512-6'  AND
ATR/ShortName = 'Thread Size' AND
CAST(
CASE ATR/AttributeType WHEN
'_Int' THEN
AI/AttributeValue END AS INTEGER) = 11

answered