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 to get specific word in a column

Query to get specific word in a column

Scheduled Pinned Locked Moved Database
databasecomtutorial
4 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.
  • J Offline
    J Offline
    JayaDurai
    wrote on last edited by
    #1

    Hi, I am need of a query to retrieve a column by trimming in a particular format. For example I have a field called UserName. The data is as follows UserName -------- user1 (user1@noreply.com) user2 (user2@noreply.com) user3 (user3@noreply.com) Here I want a query to retrieve username data as user1 user2 user3 I have to trim the content from '(' to ')' Please Let me know the query. Thanks in Advance, Jaya

    M U 2 Replies Last reply
    0
    • J JayaDurai

      Hi, I am need of a query to retrieve a column by trimming in a particular format. For example I have a field called UserName. The data is as follows UserName -------- user1 (user1@noreply.com) user2 (user2@noreply.com) user3 (user3@noreply.com) Here I want a query to retrieve username data as user1 user2 user3 I have to trim the content from '(' to ')' Please Let me know the query. Thanks in Advance, Jaya

      M Offline
      M Offline
      miah alom
      wrote on last edited by
      #2

      select substring(UserName,charindex('(',UserName), charindex(')',UserName)-charindex('(',UserName)) from UserTable is the sybase syntax. The SQL Server syntax should be equivalent. Please check.

      J 1 Reply Last reply
      0
      • M miah alom

        select substring(UserName,charindex('(',UserName), charindex(')',UserName)-charindex('(',UserName)) from UserTable is the sybase syntax. The SQL Server syntax should be equivalent. Please check.

        J Offline
        J Offline
        JayaDurai
        wrote on last edited by
        #3

        Hi alam, Thank you. I tried your query. Its working fine. The Query can be written as follows. select LEFT(UserName,CHARINDEX('(',UserName)-1) FROM UserTable Regards, Jaya

        1 Reply Last reply
        0
        • J JayaDurai

          Hi, I am need of a query to retrieve a column by trimming in a particular format. For example I have a field called UserName. The data is as follows UserName -------- user1 (user1@noreply.com) user2 (user2@noreply.com) user3 (user3@noreply.com) Here I want a query to retrieve username data as user1 user2 user3 I have to trim the content from '(' to ')' Please Let me know the query. Thanks in Advance, Jaya

          U Offline
          U Offline
          under2811
          wrote on last edited by
          #4

          Hi!!!!!!! SELECT LEFT(USERNAME,PATINDEX('%(%',USERNAME)-1) Enjoy!!!! Regards Shashank

          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