'Order By' an 'as' field

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

  1. #1

    Default Re: 'Order By' an 'as' field

    I have several working this way in my code:

    <cfquery name="GetSignups" datasource="Weddingsetgo">
    select count(showcasesignups.userid) as Registered,sum(attended) as
    ShowedUp,users.firstname,users.lastname
    from showcasesignups,users
    where users.userid=showcasesignups.userid
    group by users.userid,users.firstname,users.lastname
    order by <cfoutput>#registered#<cfoutput>
    </cfquery>

    ArtNirvana Guest

  2. Similar Questions and Discussions

    1. Updating Sort Order on a field?
      Hi i have a customer table. i am displaying them in sorted order. but now i have added 1 field call SortID. now when ever if i add a new...
    2. SQL: Order by text & numbers in same field
      Hi I have a problem, don't think there's an easy solution but here goes: I have a db text field that contains text and numbers. I need to sort my...
    3. Acrobat 6 and Field Tab Order
      When I was using Acrobat 5, it was simple to define the tab order for fields. However, in version 6.0 I do not see any means of defining a custom tab...
    4. ADO Field Order
      Douglas wrote on 05 apr 2004 in microsoft.public.inetserver.asp.db: A 4e generation relational database should not have an intrinsic field order....
    5. form field submit order
      Hello, Not sure if this is an asp or dreamweaver or a.n.other editor problem... I have a form with stacks of fields. This is submitted to a...
  3. #2

    Default Re: 'Order By' an 'as' field

    Sorry, I completely was not thinking and typed away - here is actual example
    that would actuall work:

    <cfquery username="#request.dbuser#" password="#request.dbpass#"
    datasource="#attributes.DSN#" name="checklogin">
    SELECT login
    FROM Logins
    Where login = '#Trim(login)#'<cfif EditAdmin IS "Edit"> and Login_ID <>
    #Login_ID#</cfif>
    </cfquery>

    ArtNirvana Guest

  4. #3

    Default Re: 'Order By' an 'as' field

    What database are you using?

    "Explorer5" <andrew@alconic-inc.com> wrote in message
    news:cutnls$7j5$1@forums.macromedia.com...
    > Is it possible to run a query in which the 'order by' function can use a
    > variable created by an 'as' function? I keep getting an error saying there
    > is
    > no field by that name.. See code below..
    >
    > <cfquery name="GetSignups" datasource="Weddingsetgo">
    > select count(showcasesignups.userid) as Registered,sum(attended) as
    > ShowedUp,users.firstname,users.lastname
    > from showcasesignups,users
    > where users.userid=showcasesignups.userid
    > group by users.userid,users.firstname,users.lastname
    > order by registered
    > </cfquery>
    >

    ctrl+alt+delete Guest

  5. #4

    Default Re: 'Order By' an 'as' field

    Uh, you are wrong... at least when talking about MS SQL Server.

    "Jochem van Dieten - TMM" <nomail@devnull.invalid> wrote in message
    news:cuto5t$811$1@forums.macromedia.com...
    > Explorer5 wrote:
    >> Is it possible to run a query in which the 'order by' function can use a
    >> variable created by an 'as' function?
    >
    > It is not allowed in SQL.
    >
    >
    >> <cfquery name="GetSignups" datasource="Weddingsetgo">
    >> select count(showcasesignups.userid) as Registered,sum(attended) as
    >> ShowedUp,users.firstname,users.lastname
    >> from showcasesignups,users
    >> where users.userid=showcasesignups.userid
    >> group by users.userid,users.firstname,users.lastname
    >> order by registered
    >> </cfquery>
    >
    >
    > select
    > count(showcasesignups.userid) as Registered,
    > sum(attended) as ShowedUp,
    > users.firstname,
    > users.lastname
    > from
    > showcasesignups,
    > users
    > where
    > users.userid=showcasesignups.userid
    > group by
    > users.userid,
    > users.firstname,
    > users.lastname
    > order by
    > count(showcasesignups.userid)
    >
    > Jochem
    >
    > --
    > Jochem van Dieten
    > Team Macromedia Volunteer for ColdFusion, beer and fun.

    ctrl+alt+delete Guest

  6. #5

    Default Re: 'Order By' an 'as' field

    ctrl+alt+delete wrote:
    > Uh, you are wrong... at least when talking about MS SQL Server.
    I am not.

    I am writing about SQL. Column aliasses can only be used in a
    HAVING, not in an ORDER BY, GROUP BY or WHERE. That is because if
    that were allowed the following would be undefined:

    CREATE TABLE test (ID INTEGER, test TEXT);

    SELECT ID AS test
    FROM test
    ORDER BY test

    If sorting by an alias were allowed, should the sort happen by
    the alias or by the real field? If Microsoft chooses to put
    unpredictable behaviour in their products that is their problem,
    but it is not allowed by the standard. Get a copy of ISO/IEC
    9075-2:2003 and see for yourself.

    Jochem

    --
    Jochem van Dieten
    Team Macromedia Volunteer for ColdFusion, beer and fun.
    Jochem van Dieten - TMM Guest

  7. #6

    Default Re: 'Order By' an 'as' field

    I am not going to debate whether or not it's unpredictable, it's valid for
    MS SQL server. And the example you sited is pretty straight forward despite
    your intent to create ambiguity. You are selecting and ordering the result
    set by the column 'test'.

    "Jochem van Dieten - TMM" <nomail@devnull.invalid> wrote in message
    news:cv06ao$t70$1@forums.macromedia.com...
    > ctrl+alt+delete wrote:
    >> Uh, you are wrong... at least when talking about MS SQL Server.
    >
    > I am not.
    >
    > I am writing about SQL. Column aliasses can only be used in a HAVING, not
    > in an ORDER BY, GROUP BY or WHERE. That is because if that were allowed
    > the following would be undefined:
    >
    > CREATE TABLE test (ID INTEGER, test TEXT);
    >
    > SELECT ID AS test
    > FROM test
    > ORDER BY test
    >
    > If sorting by an alias were allowed, should the sort happen by the alias
    > or by the real field? If Microsoft chooses to put unpredictable behaviour
    > in their products that is their problem, but it is not allowed by the
    > standard. Get a copy of ISO/IEC 9075-2:2003 and see for yourself.
    >
    > Jochem
    >
    > --
    > Jochem van Dieten
    > Team Macromedia Volunteer for ColdFusion, beer and fun.

    ctrl+alt+delete 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