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. sql query

sql query

Scheduled Pinned Locked Moved Database
database
3 Posts 3 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.
  • R Offline
    R Offline
    rameshdontagani
    wrote on last edited by
    #1

    hi, i have three fields in the database table p1 p2 rank 10% 20% 3 21% 40% 2 now i am passing the input as 15%...this 15% is related to 3rd rank.. so i need the o/p rank as 3.. if the p1 and p2 datatypes are varchar..then how we can we write the query for that one tgo get the rank as 3. Ramesh

    P S 2 Replies Last reply
    0
    • R rameshdontagani

      hi, i have three fields in the database table p1 p2 rank 10% 20% 3 21% 40% 2 now i am passing the input as 15%...this 15% is related to 3rd rank.. so i need the o/p rank as 3.. if the p1 and p2 datatypes are varchar..then how we can we write the query for that one tgo get the rank as 3. Ramesh

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      You haven't explained why a rank of 3 should be returned for 15% However I assume this is because 15% is between 10 and 20%. In this case, you shoul use the BETWEEN clause in your query. Why are you storing percentages in varchar fields? They are numbers, so they should be stored in numeric fields. You will run into problems every time you want to do numeric comparisons because you will need to case your varchar values to numbers.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      1 Reply Last reply
      0
      • R rameshdontagani

        hi, i have three fields in the database table p1 p2 rank 10% 20% 3 21% 40% 2 now i am passing the input as 15%...this 15% is related to 3rd rank.. so i need the o/p rank as 3.. if the p1 and p2 datatypes are varchar..then how we can we write the query for that one tgo get the rank as 3. Ramesh

        S Offline
        S Offline
        SeeSharp 0
        wrote on last edited by
        #3

        select rank from table where input between P1 and P2

        --Here 2 See Sharp-- I have not failed. I've just found 10,000 ways that won't work. :)

        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