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. Query not returning distinct value

Query not returning distinct value

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

    Hi, I am firing a query as "select distinct(trim(opp_name)) from tblOpps" but this query returns ============ Renewal Services Renewal New I want Renewal to appear only once not twice Thnaks, Mini

    R M 2 Replies Last reply
    0
    • M miniThomas

      Hi, I am firing a query as "select distinct(trim(opp_name)) from tblOpps" but this query returns ============ Renewal Services Renewal New I want Renewal to appear only once not twice Thnaks, Mini

      R Offline
      R Offline
      ritu4321
      wrote on last edited by
      #2

      there is nothing as trim in sql query. Try removing trim you will get the result.

      R 1 Reply Last reply
      0
      • R ritu4321

        there is nothing as trim in sql query. Try removing trim you will get the result.

        R Offline
        R Offline
        randz
        wrote on last edited by
        #3

        i agree with ritu4321. but if you intend to remove trailing or preceding space, you can use rtrim or ltrim. But please note that ltrim and rtrim does not remove extra spaces within the string, only those at the beginning (for ltrim) and those at the end (for rtrim). Hope this helps.

        Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code.

        1 Reply Last reply
        0
        • M miniThomas

          Hi, I am firing a query as "select distinct(trim(opp_name)) from tblOpps" but this query returns ============ Renewal Services Renewal New I want Renewal to appear only once not twice Thnaks, Mini

          M Offline
          M Offline
          Michael Potter
          wrote on last edited by
          #4

          DISTINCT should be used as a SELECT operator, not as a function. I also do not know where you get the trim() function from.

          SELECT DISTINCT
              LTRIM(RTRIM(opp_name))
          FROM
              tblOpps
          
          F 1 Reply Last reply
          0
          • M Michael Potter

            DISTINCT should be used as a SELECT operator, not as a function. I also do not know where you get the trim() function from.

            SELECT DISTINCT
                LTRIM(RTRIM(opp_name))
            FROM
                tblOpps
            
            F Offline
            F Offline
            Frank Kerrigan
            wrote on last edited by
            #5

            if you get stuck try and use the len (length function) sometimes using or importing unicode string (nvarchar etc) can cause issues. SELECT DISTINCT LTRIM(RTRIM(opp_name)), len(opp_name), len(LTRIM(RTRIM(opp_name))) FROM tblOpps

            Grady Booch: I told Google to their face...what you need is some serious adult supervision. (2007 Turing lecture) http://www.frankkerrigan.com/[^]

            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