table alias mssql problem

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

  1. #1

    Default table alias mssql problem

    I get this error:
    The column prefix 'F' does not match with a table name or alias name used in
    the query.

    with the query below

    Any ideas as to the problem?

    TIA!
    - b

    <cfquery name="getFolders" datasource="#request.datasource#">
    select F.*
    from Folders F, folderPerm P
    INNER JOIN Folders S ON S.foldermaster = F.FolderID
    where F.folderid = P.FolderID
    and P.staffID = #arguments.memberID#
    and (F.folderMaster = 0)
    order by #arguments.sortby#
    </cfquery>

    Bugsville Guest

  2. Similar Questions and Discussions

    1. Copying complete table from one MSSQL database toanother
      I will soon have to move a complete table from one database to another (including the table structure and data in the table). Is there an easy way...
    2. #40064 [NEW]: Wrong fieldnames in result (including table alias names)
      From: christoph at ziegenberg dot de Operating system: Windows XP SP2 PHP version: 5.2.0 PHP Bug Type: PDO related Bug...
    3. #33809 [Com]: pg_fetch_result: table alias produces invalid column result error
      ID: 33809 Comment by: alan8 at maths dot topology dot org Reported By: torpedo51 at yahoo dot com Status: No...
    4. Update MSSQL table with Uploaded MS Access DB
      I could use a little advice in this task. I have (potentially) dozens of users that will want to update their data on our server (MSSQL) by simply...
    5. importing a text file into a MSSQL table
      I am trying to import a tab delimited text file into a MSSQL table and am not having much luck. the challenge is that the text file has 245 fields...
  3. #2

    Default Re: table alias mssql problem

    Hi Bugs,

    Does this query work in Query Analyzer with hard-coded information?
    philh Guest

  4. #3

    Default Re: table alias mssql problem

    It does not, I get the same error.

    It all looks proper so I am at my wits end as to what the problem could be.
    Bugsville Guest

  5. #4

    Default Re: table alias mssql problem

    Take a closer look at your syntax.

    "INNER JOIN Folders S" should be "INNER JOIN Folders F"


    LL@Work Guest

  6. #5

    Default Re: table alias mssql problem

    Well, that didn't seem right to me, but I tried it anyway and got:
    "The correlation name 'F' is specified multiple times in a FROM clause."

    any other ideas? It all looks correct to me...
    Bugsville Guest

  7. #6

    Default Re: table alias mssql problem

    Well, you have two tables, Folders F and folderPerm P, in your FROM clause,
    then an INNER JOIN with a third. All three should be joined with INNER JOIN
    statements. Something like the example below:

    select F.*
    from Folders F
    INNER JOIN folderPerm P ON F.folderid = P.FolderID
    INNER JOIN Folders S ON S.foldermaster = F.FolderID
    where P.staffID = #arguments.memberID#
    and (F.folderMaster = 0)
    order by #arguments.sortby#

    Phil

    paross1 Guest

  8. #7

    Default Re: table alias mssql problem

    That resolved the error, but It is not delivering the results I am expecting.
    Maybe this will help:
    What I have is a folders table and a folderPerm (folderpermissions) table
    I want to pull the folders that the specific user has permission set to view.
    Now in the folders table, there is a masterfolder field, which is the ID of
    the folder that the specific record is a SUBfolder of.
    So the query needs to deliver all folders and subfolders that the user has
    permission to view and some folders do NOT have subfolders.

    does that make sense?

    And thanks to all who have helped so far!

    Bugsville Guest

  9. #8

    Default Re: table alias mssql problem

    Are you missing the ones that have no subfolders? Try a LEFT (OUTER) join.

    select F.*
    from Folders F
    INNER JOIN folderPerm P ON F.folderid = P.FolderID
    LEFT JOIN Folders S ON S.foldermaster = F.FolderID
    where P.staffID = #arguments.memberID#
    and (F.folderMaster = 0)
    order by #arguments.sortby#

    Phil

    paross1 Guest

  10. #9

    Default Re: table alias mssql problem

    .....or is this more like what you are trying to do?

    SELECT F.*
    FROM Folders F
    INNER JOIN folderPerm P ON F.folderid = P.FolderID
    WHERE P.staffID = #arguments.memberID#
    AND (F.folderMaster = 0)
    UNION
    SELECT S.*
    FROM Folders S
    INNER JOIN Folders F ON S.foldermaster = F.FolderID
    INNER JOIN folderPerm P ON F.folderid = P.FolderID
    WHERE P.staffID = #arguments.memberID#
    AND (F.folderMaster = 0)
    ORDER BY #arguments.sortby#

    Phil

    paross1 Guest

  11. #10

    Default Re: table alias mssql problem

    Originally posted by: paross1
    Are you missing the ones that have no subfolders? Try a LEFT (OUTER) join.

    Exactly what I needed! thanks!


    Bugsville 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