Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Help with LIKE and '_'

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
SumeetDuseja

New User


Joined: 12 Jul 2009
Posts: 9
Location: Pune

PostPosted: Fri Mar 26, 2010 6:11 pm    Post subject: Help with LIKE and '_'
Reply with quote

There is one table EMP having record as below

Table EMP

Code:
EMPno.    Name       pos_code
---------------------------------
 1         GEORGE       SA_MGR
 2         CHRIS        SABMGR
 3         ROBERT       SAAMGR
 4         DICK         SA_EMP
 5         JAMES        SABEMP


Now I want records of only those employee whose POS_CODE start with SA_ only.

If I write query like as below

select * from EMP where pos_code like 'SA_%'

then it will also fetch the emp record whoose pos_code is SABMGR or SAAMGR also because LIKE operatot SQL assume _ as a any single occurance of charecter but I want this _ itself to be match as a data.
Please help me to achieve it.
    Code:
    Back to top
    View user's profile Send private message

    PeterHolland

    Global Moderator


    Joined: 27 Oct 2009
    Posts: 2435
    Location: Netherlands, Amstelveen

    PostPosted: Fri Mar 26, 2010 6:18 pm    Post subject:
    Reply with quote

    Maybe you can use SUBSTR(pos_code,1,3) = 'SA_ '
    Back to top
    View user's profile Send private message
    GuyC

    Senior Member


    Joined: 11 Aug 2009
    Posts: 1281
    Location: Belgium

    PostPosted: Fri Mar 26, 2010 8:18 pm    Post subject:
    Reply with quote

    where Col1 LIKE 'SA+_%' ESCAPE '+'
    Back to top
    View user's profile Send private message
    View previous topic :: :: View next topic  
    Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
    Page 1 of 1

     

    Search our Forum:



    Facebook
    Back to Top
     
    Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us