Need help with building a custom query

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

  1. #1

    Default Need help with building a custom query

    Hi everybody.

    How can I create a custom query based on argument passed to CFC?

    Here is a sample code:

    <cffunction name="get_all_brands" access="remote" returntype="query">
    <cfargument name="show_hidden" type="boolean" required="no" default="false"
    />

    <cfset var all_brands_qry = "" />

    <cfif show_hidden is true>
    <cfquery name="all_brands_qry" datasource="cupoint">
    SELECT dbo.cupoint_item_brand.intBrandID as BrandID,
    dbo.cupoint_item_brand.vchBrandName as BrandName,
    dbo.cupoint_item_brand.bitActive as BrandActive
    FROM dbo.cupoint_item_brand
    </cfquery>
    <cfelse>
    <cfquery name="all_brands_qry" datasource="cupoint">
    SELECT dbo.cupoint_item_brand.intBrandID as BrandID,
    dbo.cupoint_item_brand.vchBrandName as BrandName,
    dbo.cupoint_item_brand.bitActive as BrandActive
    FROM dbo.cupoint_item_brand
    WHERE dbo.cupoint_item_brand.bitActive = 1
    </cfquery>
    </cfif>

    <cfreturn all_brands_qry />
    </cffunction>

    Is there a way to filter argument "show_hidden" through cfif and just add
    "WHERE dbo.cupoint_item_brand.bitActive = 1" to the first portion of SQL query?
    I should be easy. I come from ASP bg and just need a quick tip.

    Thank you.

    SG

    Stanley_G Guest

  2. Similar Questions and Discussions

    1. Building a custom dialog look...
      I want to build a control that alows a custom dialog border type of look. I'm implementing it now with a 3 x 3 table. Corner images and repeateable...
    2. RH9 - Building custom kernel
      Guys, I'm pretty new to this game.. so here's what I'm trying to do.. I have a stock standard RH9 (Shrike running 2.4.20-8) and I'd like Crypto...
    3. Custom Filters building
      Does anyone know where you can find a guide to building custom filters? I have a stack of books but i can't find anywhere that tells what each block...
    4. Building Custom Controls
      Hello, Is is possible to control a custom control like the asp.net server controls without making it into an assembly? For example, if my...
  3. #2

    Default Re: Need help with building a custom query

    You could do

    <cffunction name="get_all_brands" access="remote" returntype="query">
    <cfargument name="show_hidden" type="boolean" required="no" default="false" />
    <cfquery name="all_brands_qry" datasource="datasourcename">
    SELECT dbo.cupoint_item_brand.intBrandID as BrandID,
    dbo.cupoint_item_brand.vchBrandName as BrandName,
    dbo.cupoint_item_brand.bitActive as BrandActive
    FROM dbo.cupoint_item_brand
    <cfif not show_hidden>
    WHERE dbo.cupoint_item_brand.bitActive = 1
    </cfif>
    </cfquery>
    <cfreturn all_brands_qry />
    </cffunction>

    CFDEBUG 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