Coldfusion expression stored inside a variable...

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Coldfusion expression stored inside a variable...

    I have a Coldfusion expression stored inside a coldfusion variable, for example:

    <cfsavecontent time = #CreateODBCDateTime(now())#>
    if i do not put cfoutputs around #CreateODBCDateTime(now())# then the var will
    equal #CreateODBCDateTime(date)# this is what i want because that will get
    stored and then later called:

    <cfoutput>#time#</cfoutput>

    now i would like that to output as the literal date eg(01/01/99) not
    #CreateODBCDateTime(date)# but all it will do is output
    #CreateODBCDateTime(date)# so basically is there any way to parse a statement
    twice?


    JakeFlynn Guest

  2. Similar Questions and Discussions

    1. javascript, coldfusion expression
      hi guys! is there a way to embed a expression using javascript and coldfusion values? this variable is getting nut... <a...
    2. coldfusion variable inside a css doc
      You can have a dynamic style sheet. You can use cfcontent to return the MIME type text/css. The only problem with this is that it prevents the...
    3. coldfusion variable inside a css doc
      You can actually have dynamic style sheets although I've never done it. There are a few guides out there for doing it in php so i can't imagine it's...
    4. JavaScript? Putting a variable in the midst of a Regular Expression.
      I was reading a great article by Kas Thomas, "Save Yourself Some Typing with 'With'" at PlanetPDF. I really don't care much for the term guru, I...
    5. Does DB2 does implict commit inside Stored Procedure
      Hi, I written a stored procedure which does update to a table in stages. I implemented this using a while loop and udating fixed number of rows in...
  3. #2

    Default Re: Coldfusion expression stored inside a variable...

    to explain what i am trying to do a little better i will add a more complete
    example

    <cfsavecontent
    variable = "cust_query">
    select * from table1 where
    entered_date >= #CreateDate(Year(Now()), Month(Now()), 1)#
    </cfsavecontent>

    then... #cust_query# is stored in a database table as is:
    insert into table1
    values('select * from table1 where
    entered_date >= #CreateDate(Year(Now()), Month(Now()), 1)#')

    later i want to retrieve it and run it....

    <CFQUERY name="cases" datasource="#Application.DSNIntranet#">
    #custom_search.query_sql#
    </CFQUERY>
    but it says that sql does not know function #CreateDate(Year(Now()),
    Month(Now()), 1)# because obviously that is a cf function that is not getting
    parsed

    JakeFlynn Guest

  4. #3

    Default Re: Coldfusion expression stored inside a variable...

    One way of solving this is to use some kind place holders for the date in the
    saved query.
    Ex:
    select * from table1 where
    entered_date >= %CURRENT_DATE%

    While executing this query you can say

    <CFQUERY name="cases" datasource="#Application.DSNIntranet#">
    #replaceNoCase(custom_search.query_sql, "%CURRENT_DATE%",
    CreateDate(Year(Now()), Month(Now()), 1), "all")#
    </CFQUERY>

    You can such multiple place holders in the query and you should search and
    replace all these dynamic parameters at the runtime.



    basky Guest

  5. #4

    Default Re: Coldfusion expression stored inside a variable...

    Basky thank you for your reply if I use the replace like that are you sure that it will then get parsed when it is needed?
    JakeFlynn Guest

  6. #5

    Default Re: Coldfusion expression stored inside a variable...

    It sure will. There is no parsing involved here, you are just replacing the
    occurrences of a substring with in a string.
    Just want to make it clear once again, replace function is used on the saved
    query (that is stored in the database in string format), replaceAll function
    call is not part of the stored query string.


    basky Guest

  7. #6

    Default Re: Coldfusion expression stored inside a variable...

    You might look at using DB functions for this sort of thing. I don't know how
    complicated
    these queries are going to get so it's hard to say.

    select * from table1 where
    entered_date >= GetDate()

    This would work for MSSQL and could be used directly.


    OldCFer Guest

  8. #7

    Default Re: Coldfusion expression stored inside a variable...

    OldCFer thank you for your reply, the date's were a bit complicated and i had
    already done the conversions needed in CF so i wanted to reuse that code. I
    ended up using you suggestion and just doing the dates in sql thanks

    JakeFlynn 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