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. Select Query problem...

Select Query problem...

Scheduled Pinned Locked Moved Database
databasehelpquestion
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.
  • T Offline
    T Offline
    tthellebuyck
    wrote on last edited by
    #1

    I need to run a standard select but I am not getting any results. The problem is, the user input goes something like '200' and the value in the field I am comparing to is '000200' (contains leading zeros, for some reason that is beyond me). Also, the data type for the column, in my table, is char and I also need to know if my parameter needs to be of the same type. Does anyone have any suggestions/ideas to best approach this situation? Thanks, T

    T O 2 Replies Last reply
    0
    • T tthellebuyck

      I need to run a standard select but I am not getting any results. The problem is, the user input goes something like '200' and the value in the field I am comparing to is '000200' (contains leading zeros, for some reason that is beyond me). Also, the data type for the column, in my table, is char and I also need to know if my parameter needs to be of the same type. Does anyone have any suggestions/ideas to best approach this situation? Thanks, T

      T Offline
      T Offline
      The Nightcoder
      wrote on last edited by
      #2

      The one who designed the database probably thought it would be a good idea to use char. Could be right, could be wrong... but without speculating on that, here is one solution:

      create procedure FindMatch(@param varchar(100)) as
      select * from TheTable where TheKey = right('000000' + @param, 6)

      I'm assuming the actual column type is char(6). Otherwise, adjust the right invocation. Also, I've assumed you've already trimmed the parameter - otherwise, replace @param with ltrim(rtrim(@param)).

      Peter the small turnip (1) It Has To Work. --RFC 1925[^]

      1 Reply Last reply
      0
      • T tthellebuyck

        I need to run a standard select but I am not getting any results. The problem is, the user input goes something like '200' and the value in the field I am comparing to is '000200' (contains leading zeros, for some reason that is beyond me). Also, the data type for the column, in my table, is char and I also need to know if my parameter needs to be of the same type. Does anyone have any suggestions/ideas to best approach this situation? Thanks, T

        O Offline
        O Offline
        Om Prakash Pant
        wrote on last edited by
        #3

        Although the data type is char, but the data in the column is numeric then you can convert the field and then compare.

        select * from table_name where cast(field_name as int) = 100;

        Om Prakash Pant

        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