Datatype conversion in a SQL statement - need help
-
Hello , Here is the SQL I am trying to run against our database. ***************************************************** SELECT * FROM Part WHERE (Company_Abrv = 'TSBI') AND (Catalog_PartType = 'Component') AND (TypeName = 'Generic') AND (Version = 'Space Holder') AND (KeyComponentName = 'SPACER') AND ( Part_Number IN (SELECT Part_Number FROM PartAttributes WHERE (TypeName = 'Generic') AND (Version = 'Space Holder') AND (KeyComponentName = 'SPACER') AND (AttributeName = 'Inside Diameter' AND AttributeValue <= 18)) ******************************************************** the last part of the WHERE clause AttributeValue is a Varchar type column. But as we are building the SQL query dynamically we also might get integer values at times. So our query may look like the above. So in this case I am trying to convert the AttributeValue column as an int or decimal type when it has a numerical or a decimal value. so I am trying to do it like 'convert(decimal,AttributeValue) <= 18' but it doesn't accept it. could some one please help me with how do I do it? Thanks -Learner
-
Hello , Here is the SQL I am trying to run against our database. ***************************************************** SELECT * FROM Part WHERE (Company_Abrv = 'TSBI') AND (Catalog_PartType = 'Component') AND (TypeName = 'Generic') AND (Version = 'Space Holder') AND (KeyComponentName = 'SPACER') AND ( Part_Number IN (SELECT Part_Number FROM PartAttributes WHERE (TypeName = 'Generic') AND (Version = 'Space Holder') AND (KeyComponentName = 'SPACER') AND (AttributeName = 'Inside Diameter' AND AttributeValue <= 18)) ******************************************************** the last part of the WHERE clause AttributeValue is a Varchar type column. But as we are building the SQL query dynamically we also might get integer values at times. So our query may look like the above. So in this case I am trying to convert the AttributeValue column as an int or decimal type when it has a numerical or a decimal value. so I am trying to do it like 'convert(decimal,AttributeValue) <= 18' but it doesn't accept it. could some one please help me with how do I do it? Thanks -Learner