Using LIKE in SELECT ..... WHERE

Hi,
    I need to do pattern matching during SELECT so that a table field contains or is the same as an input variable. How can I accomplish this?
Regards,
Nanditha

Here is the "help" for the syntax of LIKE in SELECT statement.
<i>
f [NOT] LIKE g
Addition:
... ESCAPE h
Effect
The condition is met for a table entry if the statement "f (does not) equal the pattern in g" is true for the values of f and g. f must always be a field descriptor, and g an ABAP field. If f has the value NULL, then the result of the check for the statement is unknown. Within a pattern, there are two special characters:
'_' (underscore) stands for any single character.
'%' (percentage sign) stands for any sequence of characters, including an empty string.
Examples
Example to select all customers whose name begins with 'M':
TABLES SCUSTOM.
SELECT ID NAME FROM SCUSTOM
       INTO CORRESPONDING FIELDS OF SCUSTOM
       WHERE NAME LIKE 'M%'.
  WRITE: / SCUSTOM-ID, SCUSTOM-NAME.
ENDSELECT.
Example to select all customers whose name contains 'huber':
TABLES SCUSTOM.
SELECT ID NAME FROM SCUSTOM
       INTO CORRESPONDING FIELDS OF SCUSTOM
       WHERE NAME LIKE '%huber%'.
  WRITE: / SCUSTOM-ID, SCUSTOM-NAME.
ENDSELECT.
Example to select all customers whose name does not contain 'n' as the second character:
TABLES SCUSTOM.
SELECT ID NAME FROM SCUSTOM
       INTO CORRESPONDING FIELDS OF SCUSTOM
       WHERE NAME NOT LIKE '_n%'.
  WRITE: / SCUSTOM-ID, SCUSTOM-NAME.
ENDSELECT.
Notes
LIKE can only be used for alphanumeric database fields. In other words, table field f must have Dictionary type ACCP, CHAR, CLNT, CUKY, LCHR, NUMC, UNIT, VARC, TIMS or DATS. The comparison field g must always have type C.
The maximum length of the pattern is 2n - 1 characters, where n is the length of field f.
Trailing spaces are ignored in comparison field g. If a pattern contains trailing spaces, you must enclose it in single inverted commas ('). If your pattern is enclosed in inverted commas and you also want to include inverted commas as part of the pattern, the inverted commas in the pattern must be doubled.
You cannot use this variant in the ON addition to the FROM clause.
</i>
Regards,
Rich Heilman

Similar Messages

  • Using like with select clause

    Hi experts,
    I have a problem where i feel i should catch filtered resultset on to my internal table and i feel using LIKE.
    But if i use LIKE '%AMIT%'
    will it store
    AMIT
    amit
    Amit  ie all possible combination irrespectin of any case ?
    Will it be case insenstive or not ?

    HI,
    using like in select is case sensitive.
    do like this for ignoring the case.
    TABLES:mara.
    SELECT * from mara.
      IF mara-matnr cp 'm*'.
        WRITE:/ mara-matnr.
      ENDIF.
    ENDSELECT.
    rgds,
    bharat.

  • Using LIKE in Select query

    Hi experts,
    I am writing a Function module to get data from a table.
    Import :
    desc TYPE ZTABLE-DESCRIPTION.
    Now when desc = te*
    REPLACE ALL OCCURRENCES OF '*' IN
           desc WITH '%' .
    SELECT *
        FROM ZTABLE
        INTO CORRESPONDING FIELDS OF TABLE t_list WHERE DESCRIPTION LIKE desc.
    .. With is the table fetches all records where description starts with " te " ..  here te is case senstive
    So if description is "Test " or " TEST " or "tE" ......... so on.. i want this like to be made case in sensitive
    Coz user can search as per his/her way...
    Regards,
    Bijal

    e_sel-sign = 'I'.
    e_sel-option = 'BT'.
    e_sel-low = 'te%'.
    e_sel-high = 'TE%'.
    APPEND e_sel TO i_sel .clear e_sel.
    e_sel-sign = 'I'.
    e_sel-option = 'BT'.
    e_sel-low = 'tE%'.
    e_sel-high = 'Te%'.
    APPEND e_sel TO i_sel .clear e_sel.
    SELECT *
    FROM ztable
    INTO CORRESPONDING FIELDS OF TABLE t_list
    WHERE description IN i_sel.
    or
    SELECT *
    FROM ztable
    INTO CORRESPONDING FIELDS OF TABLE t_list
    WHERE description+0(2) in ( 'te%', 'TE%' , 'Te%', 'tE%').

  • Some photos not showing in my Camera Roll album, can only find them if I use 'Places' and select where I took the photo

    Basically as the title says, I've noticed when trying to  find some photo's I've taken in the past few months in my Camera Roll album (in the Photo's app), I can't find them anymore.
    But, if I choose 'Places' (instead of Albums at the bottom of the Photo's app) and select the place/location I took the photos, I can easily see them.
    I have an iPhone 4S on iOS 5.1. Based on the photo's missing, it appears it's happened to photos between 11th January to around 10th March. But I was definately able to seem them in the camera roll during that time (as I specifically remember a set of photo's I took I constantly referred back to around February. I can now only find them if I choose the location where I took them).
    I've reset the unit and performed a sync, but still can't see them in the Camera Roll.
    Any ideas?

    If you deleted them from photo stream, the only way to get them back in photo stream on your device is to add them to the camera roll as new photos.  If you don't need high resolution versions in photo stream, this can be done by simply opening each photo and taking a screenshot.  If you do want higher resolution versions in photo stream your options are either to email them to yourself, then save them to your camera roll, or add them to a shared photo stream album.

  • CreateNativeQuery using parameter in select LIKE statement

    Can I use setParameter on native query (createNativeQuery) using LIKE in select statement?
    I have the following code and it doesn't work:
    Query qry = manager.createNativeQuery("Select * from Type as t where t.typeid LIKE '%?1%'", Type.class);
    qry.setParameter(1, "2");
    Thanks.

    You could do this using the CONCAT function (+ ||, depending on the database). i.e. concat '%' + ?1 + '%'. You can do this in a native query, but JPQL does not allow functions in like (although some providers may support it). If your using TopLink Essentials or (TopLink/EclipseLink) you can do this using an Expression query.
    But, in general it may be better and easier to just concat "%" to your argument.
    -- James : [http://www.eclipselink.org]

  • SQL Syntax using 'LIKE'

    Hello,
    I am using with MS SQL Server.
    I use for SELECT as
    pstmtSelect = conn.prepareStatement(
    "select Id, Description from Stock where Id = ?");
    What is the syntax for using LIKE in the WHERE clause? ( I would like to use - WHERE Id LIKE ......?).
    Thanks,
    Aung.

    Thanks.
    It doesn't work with setString(1,'555%').
    It solved the problem by using - stmt.setObject(1, string, java.sql.Types.VARCHAR)
    instead of setString(1, string)
    in the PreparedStatement's "?".
    Thank you,
    Aung.

  • Get Result using LIKE operator

    Hi All,
    I am bit confused as to how to get this output using like operator :
    select * from table1 where name like 'P&C%';
    Here , since '&' is there , sql is prompting me to enter a value for C instead of giving output. I tried using escape but it is not working.
    Can anybody tell me how to overcome this problem..?
    Thanx.

    Alright,
    Here you go. In 'SQL Editor' in PL/SQL Developer:
    Pulled this off the PL/SQL Developer Manual:
    Escape character
    If you wish to use an ampersand in the SQL text that should not be interpreted as a substitution variable,
    use a double ampersand instead. The following example will retrieve all employees from the ‘R&D’
    department:
    select * from emp
    where emp.deptno in (select dept.deptno from dept
    where dname = 'R&&D')
    order by empno desc
    If the text 'R&D' had been used instead, you would have been prompted for the D variable.

  • Using -like operator to select recipients for Dynamic Distribution Group

    Dear Scriptor,
    I got few thousand of data and would like to select recipient according to the CustomAttribute1.
    Below is the sample data in my database.
    Name: User1, CustomAttribute1: aa, bb, cc
    Name: User2, CustomAttribute1: aa, bb
    Name: User3, CustomAttribute1: bb, cc, dd
    If I run the script as below,
    New-DynamicDistributionGroup -name "myDyna.bb" -RecipientFilter {(CustomAttribute1 -like 'aa*')}
    The return result is User1 and User2
    When I run the script as below,
    New-DynamicDistributionGroup -name "myDyna.bb" -RecipientFilter {(CustomAttribute1 -like 'bb*')}
    No result returned
    How can I overcome this issue?
    Thanks.

    Below are my sample data in O365.
    Type
    Identity
    UserPrincipalName
    DisplayName
    FirstName
    LastName
    CustomAttribute1
    Mailbox
    77771111
    [email protected]
    7777 #1
    7777
    #1
    a1, a2, a3
    Mailbox
    77772222
    [email protected]
    7777 #2
    7777
    #2
    a1, a2
    Mailbox
    77773333
    [email protected]
    7777 #3
    7777
    #3
    d4, a1
    Mailbox
    77774444
    [email protected]
    7777 #4
    7777
    #4
    a2, e5, f6
    Mailbox
    77775555
    [email protected]
    7777 #5
    7777
    #5
    g7, h8, i9
    Mailbox
    77776666
    [email protected]
    7777 #6
    7777
    #6
    g8, i9, a3
    I would like to create a DynamicDistributionList where CustomAttibute1 contain "a2".
    The expecting result are 77771111, 77772222 and 77774444.
    How can I write the script?
    I am using Windows Azure Active Directory Module for Windows Powershell. I run the $PSVersionTable.PSVersion and it returned me Major=4, Minor=0, Build=-1, and Revision=-1.
    This works for you case:
    New-DynamicDistributionGroup -name "myDyna.bb" -RecipientFilter {CustomAttribute1 -like '*a2*'}
    Do not use parens "()".
    ¯\_(ツ)_/¯

  • I'd like to select print paper size with using AxAcroPDFLib method depend on user

    I'd like to select print paper size with using AxAcroPDFLib method depend on user
    request. Is it possible? in AxAcroPDFLib?
    Is there any method to select print paper size in the C# programming.
    Or if you know another method, please introduce how to use.
    Thank you for your cooperation always.

    I am pretty sure that you can only do this from JavaScript or from C/C++ APIs.

  • I would like to buy a iPhone 4 unlocked from USA and take it with me to use it in Norway where I live is it gone work there? Thanks Melody

    I would like to buy a iPhone 4 unlocked from USA and take it with me to use it in Norway where I live is it gone work there? Thanks Melody

    Unlocked means unlocked, so yes.
    But, support and namely warranty coverage may not be available for you in Norway or anywhere but in the US with any iPhone purchased in the US, even an unlocked iPhone purchased in the US.

  • How do you keep the order using SELECT WHERE IN()?

    Hi,
    Is there a way to keep the order when using SELECT WHERE IN()? For example, using the following query:
    SELECT id FROM data_table WHERE id IN('56','55','54','1','7');
    The results will come back using the default order by id. 1,7,54,55,56
    When I want to keep the order used in the IN: 56,55,54,1,7
    Is there a quick way to do this in mySQL or will I be forced to order it after in code.
    Thanks

    797836 wrote:
    Hi,
    Is there a way to keep the order when using SELECT WHERE IN()? For example, using the following query:
    SELECT id FROM data_table WHERE id IN('56','55','54','1','7');
    The results will come back using the default order by id. 1,7,54,55,56In case the order by docs and comments weren't clear on this point, there is no default order and they may come back in a different order. Usually after you've tested it to exhaustion to prove otherwise, then put it in production.
    >
    When I want to keep the order used in the IN: 56,55,54,1,7
    Is there a quick way to do this in mySQL or will I be forced to order it after in code.
    ThanksUsing the in list allows oracle to have other possible data access paths than simply running the query 5 times. If for whatever reason you don't want to order the results after they come back, it may be worth your while to just run the five queries serially in the order you want, using bind variables and so having identical queries. That may seem silly on its face, but then again, we don't know the real requirements, what else is going on, if this is simplified from the real code or whether there will always be 5.

  • I would like cut out an object using the quick select tool and drop the object into another picture. Can anyone help

    I am using background pictures and want to cut out objects from other jpegs using the quick select tool and drop them into the background picture. So if i have a banana and select the object i need to copy the banana into the other background.
    Hope this makes sense.
    Gary

    Select banana. Right click>layer via copy. Move tool. Click and drag to other file. Drop on image.
    OR: load the background and banana in one stack (File>Scripts>Load File Into Stack). Select banana and layer via copy or create layer mask.
    Benjamin

  • Where is loop status stored during runtime using "loop on selected steps"

    I am trying to write a custom report that allow a technician to loop on an arbitrary set of steps and receive the results in a csv file or equivalent (without having the techs trying to change parts of the sequence, since that would violate quality controls on manufacturing testers). 
    I was hoping to be able to read a variable in the poststepcallback that shows whether the step was tested using "loop on selected steps" and having a custom output for that case.  If anyone knows how I can detect looping I would appreciate the help.
    Thanks,
    Sean

    Hey s.cooper,
    This may be a bit more tricky than it seems.  Only because the reporting, as you are aware, is, or at least should be, taken care of by the process model.  Therefore you cannot use the default reporting because you have your own process model.  Since the default reporting is part of the Sequential, Batch or Parallel process models that ship with TS then you would have to use one of those process models to get the default reporting. 
    Concerning the looping-
    Will the ops and techs be selecting to loop on a particular set of steps interactively (i.e. Execute>>Loop on selected steps)?  If you used the default sequential model you'll notice that you can Loop on Selected Steps Using the SinglePass entry point.  This does use the process model to loop on the selected steps a certain number of times.  However, Execute>>Loop On Selected Steps...  does not use the process model and just loops on the selected steps.  If you did write your own process model then you can select your entry point to Allow Interactive Execution of Entry Point.  This option is in the entry point sequence properties.  Right click the entry point and select properties.  On the Model tab you will see that option. 
    OR
    Will the ops and techs have the option set forth by your process model to select which steps to loop on?  If so then how would you loop on those steps?  Have a GoTo step that loops back to the beginning?  Have something that sets each step to loop a fixed number of loops?  There is a Step.LoopType API property that returns the Looping property for a given step as a string.  NoLooping means that the step has no looping properties set for it.  This could be used somewhere in a condition to determine which type of reporting to do.
    Hope this helps you some,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • If CASE Statement can be used just nest to 'WHERE' keyword in sql?

    HI All,
    There are 2 tables,
     dbo.headcount_smart_view & dbo.headcount_user_view,they
    are not joined i.e. there is no join between these 2 tables.
     User is trying to create the access restriction on table
    dbo.headcount_smart_view as below,
    The following case clause is just next to 'WHERE' keyword :
    CASE select distinct dbo.headcount_user_view.role_cd from
    dbo.headcount_user_view where UPPER(dbo.headcount_user_view.cmt_id) = UPPER(@Variable('BOUSER'))
    WHEN 8 THEN dbo.headcount_smart_view.l3_id In (select distinct
    dbo.headcount_user_view.divid from dbo.headcount_user_view
    where UPPER(dbo.headcount_user_view.cmt_id)=UPPER(@Variable('BOUSER')))
    WHEN 9 THEN dbo.headcount_smart_view.l4_id In (select distinct
    dbo.headcount_user_view.divid from dbo.headcount_user_view
    where UPPER(dbo.headcount_user_view.cmt_id)=UPPER(@Variable('BOUSER')))
    ELSE
    dbo.headcount_smart_view.l2_id In (select distinct
    dbo.headcount_user_view.divid from dbo.headcount_user_view
    where UPPER(dbo.headcount_user_view.cmt_id)=UPPER(@Variable('BOUSER')))
    END
    The user is getting 'syntax error', it seems that the value is not getting compared with any column hence getting the error.
    can case statment  be used just next to 'WHERE' keyword in sql? 

    I don't have the entire table query...
    but could u tell me wil the sql given below work ....
    if not, why? and what can be done to make it work ?
    SELECT * FROM Customers 
    where case select  CustomerID from customers 
    when 8 then 'Spock'
    when 9 then 'Yedi'
    else 'Jedi'
    end;
    Nope
    because of wrong syntax
    What the purpose of the case when statement here? I'm not seeing a condition in WHERE. You should use it in a condition like below
    SELECT * FROM Customers
    where case CustomerID
    when 8 then 'Spock'
    when 9 then 'Yedi'
    else 'Jedi'
    end = @SomeParameter
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Using procedure in SELECT statement

    I have a select statement that currently uses 4 functions to receive necessary values. All the functions are recursive and returns values from the same row.
    What I would like to do is replace these for function calls with 1 procedure. Does anybody know if it possible to use a procedure in this way inside a select statement?
    If so, do you have the syntax for doing this?
    E.g
    SELECT
    Mdbrd_Pkg.calculate_fixed_charge_fn(in_rc_id, ap.CONFIGSET_ID) AS FIXED_CHARGE,
    Mdbrd_Pkg.calculate_charge_rate_fn(in_rc_id, ap.CONFIGSET_ID) AS CHARGE_RATE,
    Mdbrd_Pkg.tax_liable_fn(in_rc_id, ap.CONFIGSET_ID) AS TAX_LIABLE,
    Mdbrd_Pkg.charge_unit_fn( in_rc_id, ap.CONFIGSET_ID) AS CHARGEUNIT_ID
    FROM .....

    This cannot be done. The part of the function used in the SELECT statement is the return value: procedures don't have return values (that's what makes tham procedures and not functions).
    Obviously I don't know what your code does, but you should consider putting them into a single function that returns a TYPE with four attributes and then using the TABLE() function to cast them into something you could reference in the FROM clause of a correlated sub-query. Sounds a bit messy though.
    Do these functions actually select data? Where does the recursion fit in?
    Cheers, APC

Maybe you are looking for

  • Getting error-ORA-24381: error(s) in array DML

    Hi i have written the following code to bulk insert into a database table. I am getting an error while returning the result of the bulk insert query into the collection I have tried to track it by using sql%bulk_exceptions.error_code. But the error c

  • Setting up a dsl as failover on 2600 series router

    I need to setup a failover line. the primary line is a T1 which is connected to serial interface. the secondary line is install to the FE0/1 of a 2600 series router. when i configure the nat pool IPOOL i get a error message saying that dynamic maping

  • Crystal Report DB Connection

    Hi, I want to design Custtomized reports for SAP Business One in Crystal Report. Please guide me how can I connect with the server and database so that it becomes general and I can use it in any SBO server at different client places without doing any

  • How do I correct odd page upside down while duplex printing?

    My MX870 prints every other page upside down while printing a catalog in duplex mode.  How can I correct this? The catalog was written using MSWord 2007. Obviously, I can manually duplex the catalog. I am praying there is a solution to be able to aut

  • Shift time when importing

    Hello, Apologies in advance if this has already been asked or if I've missed the solution, but I did try to search the forums for an answer first. I would like to be able to apply a time change, e.g., applying a timezone offset, when importing images