Query w/bad table structure

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

  1. #1

    Default Query w/bad table structure

    Hi,
    I am trying to query a column that has multiple values. When I export it, I
    need to have it so that each of those values is placed in its own column
    instead of them being grouped together. What might the mysql syntax be to
    accomplish this? TIA.

    rmorgan Guest

  2. Similar Questions and Discussions

    1. Copy a table in Access structure only with CF query
      Hello, I need to know how to create a new table by copying an existing table with the table structure only in a query Don't know the Syntax but...
    2. Accessing a Query in a structure
      I am creating a session variable that is a structure. Each key in the structure stores a query that I created via QueryNew. I can output the query...
    3. Query to Structure?
      Hi. I wanted to ask if someone knew how to do the following: I have a structure and a query. <cfset myStruct = StructNew()> <cfset...
    4. Creating new table with same structure as existing one
      I need to create "archive" table that will have the same structure as "production" one. When I run my program it have to create table named...
    5. query to return table structure
      hi, Is there any command or query that returns the table structure informix.
  3. #2

    Default Re: Query w/bad table structure

    Are you trying to convert a column into a row ?

    Regards
    Sojovi Guest

  4. #3

    Default Re: Query w/bad table structure

    There's no way to do this directly in a database query. You have 2 choices:

    redesign your database to fix this
    -or-
    do the conversion in Coldfusion (do the query, loop through the query creating
    a new query and separating out the values)

    If you are storing multiple values in a single field in your database, either
    comma-delimited, space-delimited, or some other way, then you aren't working
    with a normalized database structure and aren't using the database how it was
    designed (which is why you can't do this directly in a query).

    Kronin555 Guest

  5. #4

    Default Re: Query w/bad table structure

    I guess you could say that Sojovi

    The origianal column, lets call it OrigCol has these possible values
    101,102,103,104

    To start with I need to run the query to create a tab delimited file and the
    end result needs to look like:
    "101" "102" "103" "104"

    instead of : "101 102 103 104" like it does right now.


    rmorgan Guest

  6. #5

    Default Re: Query w/bad table structure

    Originally posted by: rmorgan
    I guess you could say that Sojovi

    The origianal column, lets call it OrigCol has these possible values
    101,102,103,104

    To start with I need to run the query to create a tab delimited file and the
    end result needs to look like:
    "101" "102" "103" "104"

    instead of : "101 102 103 104" like it does right now.


    See if the listqualify function allows you to use double quotes. I always use
    single, so I don't actually know.

    Dan Bracuk Guest

  7. #6

    Default Re: Query w/bad table structure

    Originally posted by: Kronin555
    There's no way to do this directly in a database query....

    No, you can do this in PostgreSQL and MS SQL. Might be able to do it in
    MySQL 5 not sure about that one.

    So the answer is switch to PostgreSQL!



    MikerRoo Guest

  8. #7

    Default Re: Query w/bad table structure

    MikerRoo, I'd be interested to see how you can do this in PostgreSQL. Could you
    post an example? I'm assuming you're proposing using a column type of ARRAY or
    a composite type... even with that I don't know how you can get what the
    original poster was asking for.

    Kronin555 Guest

  9. #8

    Default Re: Query w/bad table structure

    The basic technique is to use a UDF that parses the string into a record set.

    I don't have an example here at work (a MS SQL shop). I'll fire up the ole
    abacus at home when I get a chance, if you still need an example.

    MikerRoo Guest

  10. #9

    Default Re: Query w/bad table structure

    > The basic technique is to use a UDF that parses the string into a record set.

    Ah, gotcha. Yes, this could be handled with a UDF or stored procedure. I never
    considered that angle, but would be a good fix if changing the database schema
    is out of the question. I haven't written many UDFs or stored procs, so don't
    consider it as often as I probably should when looking for a solution to a
    problem.

    Kronin555 Guest

  11. #10

    Default Re: Query w/bad table structure

    Anyway, (as you correctly point out) if you have to do this then some DB
    designer has not done an adequate job.

    The correct thing to do is to fix the DB design and "calibrate" the original
    designer if he's within range.

    MikerRoo 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