Looking for a value in a list stored in a database tablefield

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Looking for a value in a list stored in a database tablefield

    Hello,

    I have a field in a database table that contains a comma separated list on
    numbers. In my CFQUERY I am attempting to extract records from the database
    table where a parsed number is present in the comma separated list. I have
    tried the code below, but it is throwing an error.

    variables.publicationID is the number that I am looking for in the database
    table field.
    publicationList is the name of the database table field containing the comma
    separated list of numbers.

    where <cfqueryparam value="#variables.publicationID#"
    cfsqltype="cf_sql_integer"> in publicationList

    Can anybody help?

    Many thanks,

    smnbin

    smnbin Guest

  2. Similar Questions and Discussions

    1. Flash swf Ads stored in Mysql database
      Hi Everyone, I am using Dreamweavers' Development toolkit and can upload images such as JPG and GIF files to my server and add their file name to...
    2. Directory listing stored in database
      I have an archive section of a web site that contains a bunch of text, word and PDF documents that users add and delete. I want a method to have CF...
    3. how to list all the file names in a directory in Stored Procedure
      EXEC master..xp_cmdshell 'DIR C:\*.* /b' -- David Portas ------------ Please reply only to the newsgroup -- "john" <john_ebenzer@yahoo.com>...
    4. how to list all the file names in a particular directory in Stored Procedure.
      hi Can anyone help me out !! how to list all the file names in a particular directory in Stored Procedure. I need to do this in a Stored...
    5. Hyperlinks stored in database
      <a href=<%=rsItems("HostingCompany")%>><%=rsItems("HostingCompany")%></a> -- ---------------------------------------------------------- Curt...
  3. #2

    Default Re: Looking for a value in a list stored in a databasetable field

    The only way to do it with the data model you currently have is as follows:

    WHERE publicationList LIKE '#variables.publicationID#' OR
    publicationList LIKE '#variables.publicationID#,%' OR
    publicationList LIKE '%,#variables.publicationID#,%' OR
    publicationList LIKE '%,#variables.publicationID#'

    You need to check for 4 cases:
    it's the only ID in the list
    it's the first ID in the list
    it's in the middle of the list
    it's the last ID in the list.

    The better solution would be to replace this comma-delimited list with a
    mapping table, where each row in this mapping table contains a reference to the
    main table as well as a single publicationID.

    Kronin555 Guest

  4. #3

    Default Re: Looking for a value in a list stored in a databasetable field

    Actually it could be worse than Kronin555 suggests -- if spaces are allowed
    around the commas (I've seen it more than once), then you would need up to
    <b>nine</b> conditions in your where clause.

    If you are using MySQL, you can try the FIND_IN_SET() function but I don't
    recommend it.

    As Kronin555 hinted, you would be wise to abandon this approach and normalize
    this database.

    MikerRoo Guest

  5. #4

    Default Re: Looking for a value in a list stored in a databasetable field

    A "<i>database table field containing the comma separated list of numbers.</i>"
    is an almost surefire guarantee of a bad data model. Sometimes you get stuck
    with such a bad design, but I would do everything I could to try and fix the
    model, if it is within your power.

    Phil

    paross1 Guest

  6. #5

    Default Re: Looking for a value in a list stored in a databasetable field

    Thank you all for your responses.

    Kronin555 - I used your solution in the end which appears to work okay as the
    list doesn't contain any spaces.

    paross1 - I understand your point about the bad data model and if I had a bit
    more time to fix the problem properly I would look at making some changes to
    the database structure.

    Thanks again.

    smnbin

    smnbin Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139