IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help with LIKE and '_'


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 2481
    Location: Netherlands, Amstelveen

    PostPosted: Fri Mar 26, 2010 6:18 pm
    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
    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 View Bookmarks
    All times are GMT + 6 Hours
    Forum Index -> DB2

     


    Search our Forums:

    Back to Top