Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Datatype conversion in a SQL statement - need help

Datatype conversion in a SQL statement - need help

Scheduled Pinned Locked Moved Database
databasequestionhelpannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Slow Learner
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • S Slow 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

      A Offline
      A Offline
      albCode
      wrote on last edited by
      #2

      cast(AttributeValue as decimal(20)) <= 18

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups