SQL to match a single value in a field with comma-delimited text

I have a column that can contain none, one or many recordIDs
(from another table) stored as comma-delimited text strings (i.e.,
a list). I need to retrieve all records that match a single value
within that list.
For example, if I want to match all values that equal
recordID 3, and I use ... WHERE MyColumn IN ('3') ... , I will get
all records that have EXACTLY 3 as the value of MyColumn, but not
any MyColumn records whose values include 3, if they are instances
such as "3,17" or the like.
Also using the LIKE operator -- as WHERE MyColumn LIKE '%3%'
-- will get me unwanted records with values such as 35 or 13 ...
Can I use some sort of intervening ColdFusion list processing
to output only the desired records?

Normalize your database so that your data becomes
accessible.

Similar Messages

  • Form field with comma delimited value list to cfc

    I have a form that passes a field to an action page with a
    comma delimited value.
    For instance the field name is: Program_ID
    value for program_ID is: 31, 32
    I am able to treat this variable as a list and check its
    length, and loop over the list prior to passing it to a cfc using
    the attached code:
    When I try and pass the variable as a string to a cfc and
    invoke a query, cf no longer recognizes my var as a list.
    Therefore the code attached does not function...
    Is there a specific var type that will pass through as a list
    and allow me to run the code block attached?
    thanks
    Craig

    Ok answered my own question.. Here is the answer for those
    who are interested...
    initialize var for cfc in cfinvoke statement
    <cfinvokeargument name="Program_ID"
    value="#Form.Program_ID#">
    pass argument to cfc as a string
    <cfargument name="Program_ID" type="string"
    required="true">
    use listqualify to parse list in cfc and set new var
    <cfset selectedProgramID =
    ListQualify(Program_ID,"'",",","CHAR")>
    use the new var in the following statement in sql code:
    ((Program_ID) IN (#PreserveSingleQuotes(selectedProgramID)#))
    The following code handles a form field with a single value
    or a comma delimited value.

  • Comma delimited text file using pl/sql ???

    Hi friends
    I want to create a comma delimited text file from emp table like using pl/sql program. I have oracle 8.0.4.0.0 production.
    emp.txt
    7844,TURNER,SALESMAN,7698,08-SEP-81,1500,0,30
    7876,ADAMS,CLERK,7788,23-MAY-87,1100,,20
    7900,JAMES,CLERK,7698,03-DEC-81,950,,30
    Thanks
    Sai

    Hi Justin
    I traced out the error message, is below,
    1 declare
    2 fh utl_file.file_type;
    3 d varchar2(20) := 'sample data';
    4 sql_err number(10);
    5 error_info varchar2(60);
    6 begin
    7 fh := utl_file.fopen('c:\','A.TXT','A');
    8 utl_file.put(fh,d);
    9 dbms_output.put_line('file created');
    10 d:='&urdata';
    11 utl_file.putf(fh,'\n given data is %s\n',d);
    12 utl_file.put_line(fh,'this is last line');
    13 utl_file.put(fh,'hello');
    14 utl_file.fflush(fh);
    15 utl_file.fclose(fh);
    16 exception
    17 when others then
    18 sql_err := SQLCODE;
    19 error_info := SQLERRM;
    20 dbms_output.put_line(SQL_ERR||'-'||error_info);
    21 if utl_file.is_open(fh) then
    22 utl_file.fclose(fh);
    23 end if;
    24* end;
    SQL> /
    Enter value for urdata: TEST
    old 10: d:='&urdata';
    new 10: d:='TEST';
    1-User-Defined Exception
    PL/SQL procedure successfully completed.
    Sai

  • Dynamic SQL query to get single value from list in a column

    I have two tables: tblWorkers and tblSkills. tblWorkers has a
    column, Skills, which is populated from a multiple-checkbox form
    field with one or more skill_IDs from tblSkills, so each
    tblWorkers.Skills consists of a list of one or more comma-delimited
    values. For any Skill_ID, I need to generate a listing of all
    Workers with the corresponding skill, so I have tried to do
    something along the lines of SELECT WorkerName FROM tblWorkers
    WHERE Skills IN (Skills, #FORM.Skill_ID#) ... or WHERE Skills IN
    (ListFind(Skills, #FORM.Skill_ID#)) ... etc. ??? My results (once I
    got data type mismatches out of the way) return all Workers, not
    just those with the desired Skill. There must be an easy way to do
    this ... How do people with a bit more CF/SQL experience than I
    have do this???

    quote:
    Originally posted by:
    lucapac
    I have two tables: tblWorkers and tblSkills. tblWorkers has a
    column, Skills, which is populated from a multiple-checkbox form
    field with one or more skill_IDs from tblSkills, so each
    tblWorkers.Skills consists of a list of one or more comma-delimited
    values. For any Skill_ID, I need to generate a listing of all
    Workers with the corresponding skill, so I have tried to do
    something along the lines of SELECT WorkerName FROM tblWorkers
    WHERE Skills IN (Skills, #FORM.Skill_ID#) ... or WHERE Skills IN
    (ListFind(Skills, #FORM.Skill_ID#)) ... etc. ??? My results (once I
    got data type mismatches out of the way) return all Workers, not
    just those with the desired Skill. There must be an easy way to do
    this ... How do people with a bit more CF/SQL experience than I
    have do this???
    As Kronin implied, we normalize our databases. If you don't
    understand that answer, the book "Database Design for Mere Mortals"
    is often mentioned on this forum.

  • ADF 11g- Selecting Maximum value of a field on Commit Button

    Hi
    I am trying to assign a value to a field on form by selecting max(id)+1 from database table on commit button.
    It assign the value to field but try to commit before assigning value.
    code is like this:-
    public String commandButton2_action() {                  ////////////////a commit button.
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("Commit");
    commandButton3_action();////////////Retrieve the maximum value from database.
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty()) {
    return null;
    return null;
    please do guide. what to do.
    Regards
    M Niaz

    Thanks,
    I know, that's why i am try to put this on save button instead on any other.
    But this is not an issue whether to use sequence or max()+1. I can use sequence instead but even then i have to get the nextvalue on form before commit.
    and i have to put that on commit button.
    Commit but try to commit the form before getting anything from DB.
    M Niaz

  • How to replace blank values in DATE field with 00000000

    Hi
    I have a DSO with Date field in which there are blank values. I want to replace the blank values in the DSO for date field with 00000000. Because of this blank values in the DSO the report is giving an ORA error.
    How do we replace the blank values in the DSO for historical data and also the new loads?
    Please advise.
    Thank you.
    Regards,
    Pavan.

    Hi Suman,
    I'm trying to run a query built on a DSO. The DSO has a field 'Start Date'. This Start Date InfoObject has a reference Char as 0DATE.
    This Start Field has blank values due to which I'm getting the ORA-01722 error. I came across many threads with same topic of discussion. As mentioned in one of the Threads I have written a program to update 'Start Date' with 00000000. The code wriiten is "UPDATE /BIC/AZ_MONINV00 SET /BIC/ZSTR_DTE = '00000000' where /BIC/ZSTR_DTE = ' '.
    Now when I see the data in the active data table of DSO the blank value is replaced with '00000000'.
    But If I right click on the DSO click on display data the 'Start Date' field is blank. And now the Query also gets executed without any error. But in the output of the query the 'Start Date' Field has "#" values.
    Can anyone suggest on how to remove these "#" values in the report?

  • Displaying data from a list into a single field with comma separated values

    Hi,
    I have a requirement to change a report with an XML structure (simplified version) as below
    <Protocol>
    <ProtocolNumber>100</ProtocolNumber>
    <SiteName>Baxter Building</SiteName>
    <ListOfActivity>
    <Activity>
    <Description>Communication Memo Description.</Description>
    <Name>James</Name>
    </Activity>
    <Activity>
    <Description>Visit 4</Description>
    <Name>James</Name>
    </Activity>
    <ListOfActivity/>
    </Protocol>
    On the report I need to display all the 'Names' for each of the Child (Activities) in a single field at the Parent (Protocol) level, with each Name separated by a comma.
    How do I go about getting this to work?
    Thanks

    Take a look at this: http://blogs.oracle.com/xmlpublisher/entry/inline_grouping
    You could do this (ofcourse, you will need to add extra logic to ensure that there is no comma added after the last name..)
    <?for-each@inlines:Name?><?.?><?', '?><?end for-each?>
    Thanks,
    Bipuser

  • SQL*Loader . A column value in data file contains comma(,)

    Hi Friends,
    I am getting an issue while loading a csv file to database.
    A column in datafile contains a comma .. how to load such data?
    For ex, a record in data file is :
    453,1,452,N,5/18/2006,1,"FOREIGN, NON US$ CORPORATE",,,310
    Here "FOREIGN, NON US$ CORPORATE" is a column and contains a , in the value.
    I have specified optionally enclosed with " also.. but still not working
    Here is my control file:
    options (errors=100)
    load data
    infile 'TAX_LOT_DIM_1.csv'
    badfile 'TAX_LOT_DIM_1.bad'
    replace
    into table TAX_LOT_DIM
    fields terminated by ',' optionally enclosed by '"'
    trailing nullcols
    TAX_LOT_DIM_ID ,
    TAX_LOT_NBR ,
    TAX_LOT_ODS_ID ,
    RESTRICTION_IND ,
    LAST_UPDATE_DTM ,
    TRAN_LOT_NBR integer,
    MGR_GRP_CD optionally enclosed by '"' ,
    RESTRICTION_AMT "TO_NUMBER(:RESTRICTION_AMT,'99999999999999999999.999999999999')" ,
    RESTRICTION_INFO ,
    SRC_MGR_GRP_CD
    Problem is with MGR_GRP_CD column in ctrl file.
    Please reply asap.
    Regards,
    Kishore

    Thanks for the response.
    Actually my ctrl file is like this with some conversion functions:
    replace
    into table TAX_LOT_DIM
    fields terminated by ',' optionally enclosed by '"'
    trailing nullcols
    TAX_LOT_DIM_ID "TO_NUMBER(:TAX_LOT_DIM_ID ,'999999999999999.99999999')",
    TAX_LOT_NBR ,
    TAX_LOT_ODS_ID "to_number(:TAX_LOT_ODS_ID ,'999999999999999.999999')",
    RESTRICTION_IND ,
    LAST_UPDATE_DTM "to_date(:LAST_UPDATE_DTM ,'mm/dd/yyyy')",
    TRAN_LOT_NBR integer, --"TO_NUMBER(:TRAN_LOT_NBR,'999999999999999.99999999999999999')",
    MGR_GRP_CD char optionally enclosed by '"' ,
    RESTRICTION_AMT "TO_NUMBER(:RESTRICTION_AMT,'99999999999999999999.999999999999')" ,
    RESTRICTION_INFO ,
    SRC_MGR_GRP_CD
    For char columns , even i dont give any datatype, i think it will work.
    And pblm is not with this hopefully.
    Thanks,
    Kishore

  • Field with comma separated values to be split into Rows using a Query

    Thanks for the Reply.. I also have to Decode each of the spilt values with some text..
    replace(disc_topics,',',chr(10)) A from XYZ
    Disc_topics values are '01,02,03,04,05'
    this has to be done in SQL
    01 Test1
    02 Test2
    03 Test3
    04 Test4

    select replace( replace( replace( replace( '#' || '01,02,03,04,05,10,11', ',', ',#'), '#0','#'),'#','Test'),',',chr(10)) A from XYZ

  • How can I display only one value of a field with two or more values?

    Post Author: skiabox
    CA Forum: Crystal Reports
    I have a field in my report with 2 or more values (depending of another field id).For example for id = 1 the report gives me 2 names in that field.For id = 3 the report gives me 3 names in that field.I want to display only one of these names in the id row.The selection of name is random.Thanks!

    Hello Tim,  would barely fit in this situation since this code resides on the client’s interaction side of things. I’d recommend using JavaScript for this matter, e.g. var Data_FName1 = document.getElementById(‘Data_FName1’).value;. If you still opt for using CFML, then you’d go for proxying your JavaScript code to a CFC.

  • Recuperate value of new field with a BAdI

    Hi everybody,
    I am beginner in ABAP.
    Currently I have create a new field in SAP CRM thanks to EEWB (Easy Enhancement Workbench). This field is visible is the screen of SAP (tcode BUP3).
    I would to recuperate value of this new field at the time when user save a new value.
    I have tried to recuperate value in the good table but I obtain the previous value.
    I have no idea how to do this !
    Do I need to use "dynpro" ?
    Thank you by advance for your help !
    Best regards,
    Rémi

    Try
      CALL FUNCTION 'BUP_MEMORY_BUT000_GET'
        EXPORTING
          iv_partner_guid = l_guid
        IMPORTING
          es_but000       = ls_but000
        EXCEPTIONS
          not_found       = 1
          parameter_error = 2
          OTHERS          = 3.
      IF sy-subrc EQ 1 .
        CALL FUNCTION 'BUP_BUT000_SELECT_WITH_GUID'
          EXPORTING
            i_partner_guid    = l_guid
          IMPORTING
            e_but000          = ls_but000
          EXCEPTIONS
            not_found         = 1
            bpext_not_entered = 2
            OTHERS            = 3.
      ENDIF .
    Edited by: Arseni Gallardo on Sep 19, 2011 5:55 PM

  • Abap code to replace the bank values of Date Field with 20990101

    Please correct my abap code I am just trying to replace the bank values of Dataefield to 20990101 but i am getting the error invalid dataformat '00000000 '. Please correct my IF statement so that I can get this resolved
    IF    SOURCE_FIELDS-DATETO = '00000000 '
          RESULT = '20990101'.
    ENDIF.
    Thanks'
    Soniya

    Hi Soniya,
    You can use one of the following:
    IF SOURCE_FIELDS-DATETO =  ' '.
    RESULT = '20990101'.
    ENDIF.
    or
    IF SOURCE_FIELDS-DATETO IS INITIAL.
    RESULT = '20990101'.
    ENDIF.
    or
    IF SOURCE_FIELDS-DATETO = '00000000'.
    " THERE WAS A SPACE IN YOUR CODE.
    RESULT = '20990101'.
    ENDIF.
    Regards,
    Satya

  • Convert column values into a row with a delimiter

    Hi Gurus,
    This may be a trivial question to you. I have an internal table itab with a column called plant, internal table has 'n' records, by the end of loop, I need to convert the column into a row delimited by comma into one row (one field). This needs to be dynamic without hard-coding.
    Plant
    1000
    2000
    3000
    4000
    5000 ....
    n....
    Expected result of the field:
    field1 value: 1000,2000,3000,4000,5000,...n
    Let's set a limit to the field say it can hold upto 500 chars.
    Thanks,
    GP.

    Hi,
    I've already tried this:
      ELSEIF <fs_dms_cv>-zca_cv_attr_ind = c_multiple.
      w_plant = <fs_plant_ele>-werks.
      concatenate w_string w_plant
                    into w_string separated by c_delimiter.
          IF w_end_fl = c_on.
          w_tabname = <fs_dms_cv>-dbtabname.
           ASSIGN (w_tabname) TO <fs_tabname>.
            IF sy-subrc = 0.
             ASSIGN COMPONENT <fs_dms_cv>-name_komp OF 
                STRUCTURE <fs_tabname> TO <fs_destination>.
                        IF sy-subrc = 0.
                          <fs_destination> = w_string.
                        ENDIF.
            ENDIF.
    There are 2 issues here: One is that after first plant there will be two commas inserted, after that it's consistent. Secondly the key word concatenate is against our code standards.
    Please let me know if there is any other way of doing this.
    Thanks.

  • How to compare single value with multiple values

    In my query I have something like this:
    A.SOR_CD=B.SOR_CODE where A and B are 2 different tables. This condition is in the where clause. The column in table A has single values but some values in table B have multiple comma separated values (822, 869, 811, ..).  I want to match this single
    value on the left side with each of the comma separated values. Please let me know how will I be able to do it. The number of comma separated values on the right side may vary.

    Hi MadRad123,
    According to your description, you want to compare single value with multiple values in your query. Right?
    In this scenario, the table B has comma separated values, however those comma separated values are concatenated into a string. So we can use charindex() function to return the index of the table A value. And use this index as condition in
    your where clause. See the sample below:
    CREATE TABLE #temp1(
    ID nvarchar(50),
    Name nvarchar(50))
    INSERT INTO #temp1 VALUES
    ('1','A'),
    ('2','A'),
    ('3','A'),
    ('4','A'),
    ('5','A')
    CREATE TABLE #temp2(
    ID nvarchar(50),
    Name nvarchar(50))
    INSERT INTO #temp2 VALUES
    ('1','a,A'),
    ('2','A,B'),
    ('3','c'),
    ('4','A,C'),
    ('5','d')
    select * from #temp1 a inner join #temp2 b on a.ID=b.ID
    where CHARINDEX(a.Name,b.Name)>0
    The result looks like below:
    Reference:
    CHARINDEX (Transact-SQL)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Compares single value content property to single value property

    Hi,
    I am using WLPS 3.2 with weblogic apps 5.1.
    This is when regarding content selection rules. When u go into the rules
    management and try to create a content selection rule : Then display content
    based on:
    we see 3 templates to choose from. Now if u look at template 2 it says
    :Value with Property Example
    This template compares a single-value content property to another
    single-value property. content.investor_type equals user.investor_type
    It says this template compares "single value" content property to another
    "single-value property". What i did was set up a rule that comared a single
    value content property to a "multiple" value user property (i.e. the user
    property was allowed to have multiple values-check boxes). The rule was set
    up fine. When i ran the rule with the <pz:contentselector> tag it dint
    return the desired content object. Now if i set up the same rule to match a
    single valued user property then it worked!!! Could you please let me know
    why this happens and is this a limitation of the tool. What is an
    alternative solution for me to compare a content property to a multi valued
    user property.
    Thanks,
    --Kapil

    Hi Kapil,
    You're correct on all counts. This workaround does move the content
    selection into the JSP, rather than using a rule -- which is not ideal.
    Also, your suggestion to build one query string to cut down on the number of
    database calls is a good improvement.
    - Ginny
    "kapil khanna" <[email protected]> wrote in message
    news:[email protected]...
    Hi Ginny,
    I really appreciate ur response. This work around was not knew to me. Iwas
    expecting a better work around from some reasons:
    i) The definition of this rule is hard coded and not administered thu the
    tools interface.
    ii) There are multiple database calls for each property value retrieved
    every time the <cm:select> tag is executed which is very expensive.
    iii) The query that i build for the <cm:select> or <pz:contentQuery> tag
    doesnt support the in statement.
    My work around was something like this:
    Build the query string first which would look something like this
    CONTENT.interest like '*Science*' || CONTENT.interest like '*Astronomy*'
    Then run the <cm:select> or <pz:contentQuery> tag so that i have only one
    database call.
    Considering the user has 2 interests chosen Science and astronomy. I usethe
    like so that CONTENT can be tagged to accomodate multiple values which is
    very possible in a real life situation. For eg: <meta name="interest"
    content="Science,Astronomy" >
    Is this a better work around or am i totally out of line.
    Thanks for your help and time
    --Kapil
    "Ginny Peterson" <[email protected]> wrote in message
    news:[email protected]...
    Hi Kapil,
    Yes -- this is a limitation with the phrase templates. The "Value with
    Property" phrase template compares a single-value content property to
    another single-value property. What's key here (and often overlooked)
    is
    that fact that the property you're using must be a single-valueproperty.
    >>
    There is a workaround using the <cm:select> tag rather than the <pz>tags.
    Basically, it involves getting a list of the values for yourmultiple-value
    property, and iterating over that list, selecting the content for each
    of
    the items in the list.
    Here's some sample code. Assume you have a text, multiple, unrestricted
    property called "MyInterests" in property set "TestPropertySet"; a user
    might have values like this: "Science, Astronomy, Cooking".
    <%@ page extends="com.beasys.commerce.axiom.p13n.jsp.P13NJspBase"%>
    <%@ page import="com.beasys.commerce.content.ContentHelper"%>
    <%@ taglib uri="es.tld" prefix="es" %>
    <%@ taglib uri="cm.tld" prefix="cm" %>
    <%@ taglib uri="um.tld" prefix="um" %>
    <!-- Get the user and group names -->
    <%
    String userName = (String)getSessionValue(SERVICEMANAGER_USER,request);
    String groupName = (String)getSessionValue(SERVICEMANAGER_SUCCESSOR,
    request);
    %>
    <!-- Get the profile for the user -->
    <%
    // Check to see if logged in, then getProfile for the user with groupas
    successor
    if(getLoggedIn(request))
    %>
    <um:getProfile scope="session" profileKey="<%= userName %>"
    successorKey="<%= groupName %>" />
    <%
    else // use the default profile for the group
    %>
    <um:getProfile scope="session" profileKey="<%= groupName %>"
    groupOnly="true" />
    <%
    %>
    <!-- Get the property value for the user -->
    <um:getProperty id="areas" propertySet="TestPropertySet"
    propertyName="MyInterests" />
    <br><br>Interests for <%= userName %>:
    <%
    // Multi-valued properties are retrieved as an ArrayList, so cast to a
    Collection so we can iterate through
    Collection c = (Collection)areas;
    String queryString;
    Iterator i = c.iterator();
    while(i.hasNext())
    String nextVal = (String)i.next();
    queryString = "CONTENT.interests == '" + nextVal + "'";
    %>
    <cm:select contentHome="<%= ContentHelper.DEF_CONTENT_MANAGER_HOME %>"
    query="<%= queryString %>" id="docList"/>
    <es:forEachInArray id="aDoc" array="<%= docList %>"
    type="com.beasys.commerce.axiom.content.Content">
    <li>Matched document message:
    <cm:printProperty id="aDoc" name="message" encode="html"/>
    </es:forEachInArray>
    <%
    %>
    FYI, this limitation is not present in WLCS 3.5; it's much more flexiblein
    terms of using mutli-valued properties (and multi-valued meta tags) in
    rules.
    I hope this helps!
    - Ginny
    "kapil khanna" <[email protected]> wrote in message
    news:[email protected]...
    Hi,
    I am using WLPS 3.2 with weblogic apps 5.1.
    This is when regarding content selection rules. When u go into the
    rules
    management and try to create a content selection rule : Then displaycontent
    based on:
    we see 3 templates to choose from. Now if u look at template 2 it says
    :Value with Property Example
    This template compares a single-value content property to
    another
    single-value property. content.investor_type equalsuser.investor_type
    It says this template compares "single value" content property toanother
    "single-value property". What i did was set up a rule that comared asingle
    value content property to a "multiple" value user property (i.e. the
    user
    property was allowed to have multiple values-check boxes). The rule
    was
    set
    up fine. When i ran the rule with the <pz:contentselector> tag it dint
    return the desired content object. Now if i set up the same rule to
    match
    a
    single valued user property then it worked!!! Could you please let me
    know
    why this happens and is this a limitation of the tool. What is an
    alternative solution for me to compare a content property to a multivalued
    user property.
    Thanks,
    --Kapil

Maybe you are looking for

  • Photo Booth Crashes My Whole System

    And yet... iChat works fine with my camera and never has issues OKay, so I've googled, searched the discussions... and haven't found anybody with the same issue Not only does photobooth crash, but my entire system is crashed to where I'm told to powe

  • More about software updates on macbook air

    I had posted question on Maverick update issues of my macbook air purchased today. I received 2 responses; however, I could not post my further clarification against the same: got exception! My questions are: (1) While Maverick can be downloaded (I d

  • How to Minimize Java Applications

    how to mininize my java apps for nokia 2700 classic Moderator's Note: This post was edited. A more appropriate subject was provided. Solved! Go to Solution.

  • How can widget be used with SAP EP?

    hi, If any one  can tell me how we can use widget with SAP EP and the related scenarios.The steps to do so and the docs to refer to thanks

  • Dymanic JDBC connection for mulitple application..

    Hi, I am developing an application which using dynamic JDBC connection when user login it's provide the username, password and JDBC datasource and it's work fine in my main application. But when I drop my other application Jar file into that main app