Wrapper cffunction for query

Hello,
I am trying to write a wrapper function to be able to work with queries in cfscript (I deal with CF MX7). The SQL string can be assembled and passed to the function as an argument. Here is the function:
<cffunction name="QUERY" access="public" returntype="query">
  <cfargument name="SQLString" type="string" required="yes">
  <cfargument name="Datasource" type="string" required="no" default="#this.dsn#">
  <cfargument name="dbType" type="string" required="no" default="">
  <CFQUERY NAME="QryToReturn" Datasource="#arguments.Datasource#" dbtype="#arguments.dbType#">
    #preserveSingleQuotes(arguments.SQLString)#
  </CFQUERY>
  <cfreturn QryToReturn>
</cffunction>
When it's as simple as this it works:
<cfscript>
Variables.iMyValue = 10;
sSQL = "SELECT * FROM t_test WHERE field1 = #Variables.iMyValue#";
Variables.qry1 = QUERY(SQLString: sSQL, DATASOURCE: Application.sDataSrc, DBTYPE: Application.sDBType);
</cfscript>
However I want to add cfqueryparam stuff to the queries and here is where I get errors.
I tried two ways to assemple the SQL:
<cfscript>
Variables.iMyValue = 10;
//this way the function gets value 10
sSQL1 = "SELECT * FROM t_test WHERE field1 = < cfqueryparam value=#Variables.iMyValue# cfsqltype='cf_sql_integer'>";
//this way the function gets a variable
sSQL2 = "SELECT * FROM t_test WHERE field1 = < cfqueryparam value=##Variables.iMyValue## cfsqltype='cf_sql_integer'>";
Variables.qry1 = QUERY(SQLString: sSQL1, DATASOURCE: Application.sDataSrc, DBTYPE: Application.sDBType);
Variables.qry2 = QUERY(SQLString: sSQL2, DATASOURCE: Application.sDataSrc, DBTYPE: Application.sDBType);
</cfscript>
Either way results in the same server error:
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Oracle][ODBC][Ora]ORA-00936: missing expression
Could anybody tell me what I am doing wrong?
Thanks,
Alex

Passing the cfqueryparam tag within a string neutralizes it. As a general rule, ColdFusion wont evaluate tags that are enclosed within a string.
It is better to place the tag within the query in the function. Then pass the rest of the SQL script as a string. Something like this:
<cffunction name="QUERY" access="public" returntype="query">
  <cfargument name="SQLString" type="string" required="yes">
  <cfargument name="fieldValue" type="numeric" required="yes">
  <cfargument name="Datasource" type="string" required="no" default="#this.dsn#">
  <cfargument name="dbType" type="string" required="no" default="">
  <CFQUERY NAME="QryToReturn" Datasource="#arguments.Datasource#" dbtype="#arguments.dbType#">
    #arguments.SQLString#
WHERE field1 = <cfqueryparam value="#arguments.fieldValue#" cfsqltype="cf_sql_integer">
  </CFQUERY>
  <cfreturn QryToReturn>
</cffunction>
<cfscript>
variables.iMyValue = 10;
sSQL = "SELECT * FROM t_test";
Variables.qry = QUERY(SQLString: sSQL, variables.iMyValue, DATASOURCE: Application.sDataSrc, DBTYPE: Application.sDBType);
</cfscript>

Similar Messages

  • How to create the layout for query in Bex 3.5

    Hi All,
    i have one requirement to do layout for query. Report like after passing the variable values and then they will select the required layout. It has to get output according layout selection fields.
    i have no idea about how to create layout.
            thanks in advance...
    Thanks & Regards,
    Mallikarjuna.k

    Hi Gregor,
    In the note 1149346 that you have mentioned, it says -
    You must start the input-ready query in change mode.
    BEx Analyzer: In the properties of the analysis grid, the switch
    "Suppress new rows" must not be set.  Furthermore,
    the switch "Allow entry of plant values"
    must be set in the local query properties.
    I have not seen this setting Allow entry of plant values in a query - can you tell what is refers to?

  • Error: Load operation failed for query 'GetAuthenticationInfo'. The remote server returned an error: NotFound.

    Hello,
    I have a lightswitch web-application in development, which I need to copy from one computer to the other. I have tried doing it both through Git and by simply copying the solution and opening the project on another machine. The project builds without errors,
    but when I try to debug it, it opens a web-browser, loads to 100% and pops up an error - Load operation failed for query 'GetAuthenticationInfo'. The remote server returned an error: NotFound.
    Now, I have tried repairing Visual Studio on my machine, reinstalling .NET framework and setting  <basicAuthentication enabled="false" /> in web.config, yet it still does not run.
    When using Fiddler, it shows an error while loading the application - "HTTP/1.1 500 Internal Server Error" , which I honestly don't know what it means.
    The application uses ComponentOne and Telerik modules, but they are both installed on both machines. 
    The application does run perfectly on the original machine, but it is not working on any other one.
    Both machines are using Win 8.1 and Visual Studio 2013 Update 4.
    I have tried to look this up online, but most people's problem are when they are deploying the app, not just debugging. I would be really happy for any help with this issue.
    Thanks!

    I have the same problem on one of my development machines. Whenever I create a new project, the System.IdentityModel.Tokens.Jwt nuget package is not referenced properly. The project compiles correctly but you are not able to debug as I get the same error
    as you.
    If you open up your references and there is an error next to any of your references make sure that you correct them. In the case of the jwt reference error, I have to remove the jwt reference and then add it back from the packages folder.
    This may not be your problem but could point you in a direction?

  • Transaction Code assignment for Query created in SQVI

    Dear All,
    Good morning I hope you are doing great...
    Can any body help me out to assign transaction code for Query which was created through SQVI transaction.
    Regards,
    Murali.

    Hi Murali Mohan
    1>go to SQVI t code and  enter your query name and press enter
    2>In the menu path select Quick view--> additional functions-->Generate Program
    3>After Generating the program In the menu path select Quick view--> additional functions-->Display report Name
    4>Now in se38 enter the report name in Program field and execute
    5>You will get the Initial Selection screen of the report . Go to Menu of System -->Status
    6> Note down the Program name and Screen number
    7>Go to SE93 and Create a Z tcode for the query, Enter the description  and importantly you have to select the 2nd Option radio Button Program and Selection Screen (Report Transaction) and Press enter
    8>In the next screen enter the Report name In Program field and enter the screen number
    9>In the classification Section select Professional user  Transaction
    10>In GUI support section select all the options  i.e SAPGUI for HTML,Java,Windows
    and save
    the system will ask for Package select your package if not there then select local object
    now execute the Z tcode your report will run sucessfully
    Regards
    Vijay hebbal

  • Change logs for query...........

    Hi,
    How to check the logs for query changes. Means which user has done what change.In properties we get the last user only.
    Is there any way to check the full history of changes?
    Can we change that in some transport request?
    Bye,
    Jeetu

    Hi,
    There is no such facilities available to find, which user has done what changes in the query. you can only get the last changed 's user name of query. in transport request also you cannot change the query.
    To add, check out this:
    Tcode SQ01>select 'Environement' from the menu>Directories>All Queries
    in the popup window, select a query and click on 'Display' button. you would get some useful information about that query
    Bye

  • Are Cube organized materialized view with Year to Date calculated measure eligible for Query Rewrite

    Hi,
    Will appreciate if someone can help me with a question regarding Cube organized MV (OLAP).
    Does cube organized materialized view with calculated measures based on time series  Year to date, inception to date  eg.
    SUM(FCT_POSITION.BASE_REALIZED_PNL) OVER (HIERARCHY DIM_CALENDAR.CALENDAR BETWEEN UNBOUNDED PRECEDING AND CURRENT MEMBER WITHIN ANCESTOR AT DIMENSION LEVEL DIM_CALENDAR."YEAR")
    are eligible for query rewrites or these are considered advanced for query rewrite purposes.
    I was hoping to find an example with YTD window function on physical fact dim tables  with optimizer rewriting it to Cube Org. MV but not much success.
    Thanks in advance

    I dont think this is possible.
    (My own reasoning)
    Part of the reason query rewrite works for base measures only (not calc measures in olap like ytd would be) is due to the fact that the data is staged in olap but its lineage is understandable via the olap cube mappings. That dependency/source identification is lost when we build calculated measures in olap and i think its almost impossible for optimizer to understand the finer points relating to an olap calculation defined via olap calculation (olap dml or olap expression) and also match it with the equivalent calculation using relational sql expression. The difficulty may be because both the olap ytd as well as relational ytd defined via sum() over (partition by ... order by ...) have many non-standard variations of the same calculation/definition. E.g: You can choose to use or choose not to use the option relating to IGNORE NULLs within the sql analytic function. OLAP defn may use NASKIP or NASKIP2.
    I tried to search for query rewrite solutions for Inventory stock based calculations (aggregation along time=last value along time) and see if olap cube with cube aggregation option set to "Last non-na hierarchical value" works as an alternative to relational calculation. My experience has been that its not possible. You can do it relationally or you can do it via olap but your application needs to be aware of each and make the appropriate backend sql/call. In such cases, you cannot make olap (aw/cubes/dimensions) appear magically behind the scenes to fulfill the query execution while appearing to work relationally.
    HTH
    Shankar

  • How to Create PLD for Query Report

    Hi,
    We have designed some queries for daily inward / outward register.
    For taking Print we need to export data to XL and then need to take print.
    Want to set Print layout for Query based report.

    hello
    after execting the query u ca see  save button click on it write query name and query category as general then again click on save button after that just click on open then u select the  query and just click on create report and u can see name of ur query and just click on user report and click ok
    now go to tool .query->select query print layout--ouble click on ur saved query then ur pld will open set it with its propertites and layouts pls close the thread if ur problem is solved
    thank u
    ragards
    jenni

  • Need help with LikeFilter for querying the keyset instead of value

    Hi,
    I'm looking for help with the LikeFilter.
    I need to query the cache to get all entries with key starting with a particular string.
    I could see samples using LikeFilter for querying the values in the cache but not the keyset.
    Can someone help?
    E.g:
    Cache Entries:
    abc123 - value1
    abc234 - value2
    bcd123 - value3
    I want to get all entries with key starting with 'abc'.
    thanks,
    rama.

    NJ, thanks for the quick reply.
    I tried something similar (as below) but this code gives me 'java.lang.NoClassDefFoundError: com/tangosol/util/ValueExtractor'.
    KeyExtractor extractor = new KeyExtractor("getKey");
    Filter filter = new LikeFilter(extractor, id+":%",'-',false);
    -rama.
    Edited by: 911950 on Feb 2, 2012 1:18 PM

  • Variable Screen for query view is hidden

    Hi All,
       I caome across an old query in BW 3.5 which is haiving some mandatory variables. There is a query view for the same query but when i am executing the query view i didn't got any variable screen and its running for some predefined value. How one can hide the variable screen for query view.
       How can i achieve the same for a BI 7 query view.  Please guide.
    Regards:
    Jitendra

    Hi Rakesh,
        What you said is right but my concern is that next time when i open the query view variable screen shouldn't appear ie should run with previously stored variable values. I am working with BI 7 query view. Please guide.
    Regards:
    Jitendra

  • Building Cascading Lists for Query Screens with ADF Business Components.

    I build “Cascading Lists for Query Screens with ADF Business Components”. When I to select master list first working fine, but when I to select master list second returned error : JBO – 25013 : Too many objects match the primary key oracle.jbo.key[CN]. CN dependences with key to detail list (Countries in this case). Please help me.
    Andrew.

    You would have a better chance, that someone answers your question, if you choose the right forum:
    JDeveloper and ADF

  • Building Cascading Lists for Query with ADF Business components and JSP

    I build “Cascading Lists for Query Screens with ADF Business Components”. When I to select master list first – Ok, but when I to select master list second returned error : JBO – 25013 : Too many objects match the primary key oracle.jbo.key[CN]. CN dependences with key to detail list (Countries in this case). Please help me.
    Excuse me for my English.
    Andrew.

    You would have a better chance, that someone answers your question, if you choose the right forum:
    JDeveloper and ADF

  • Error on Transaction Code for Query

    Hello, Masters
    I have a problem with a transaction for query, I hope that you can help me.
    On transaction SE93 I create transaction ZRH11,
    I choose transaction with parameters.
    On Transaction field the value is  START_REPORT
    The checkbox skip initial screen is marked
    The checkbox for SAP GUI for html, java and windows are marked
    Parameter D_SREPOVARI-REPORTTYPE = 'AQ'.
    Parameter D_SREPOVARI-REPORT     = 'RHCYA' is the users group this group is global
    Parameter D_SREPOVARI-EXTDREPORT = 'ZIT0015' is the query
    Parameter D_SREPOVARI-VARIANT    = 'STANDARD'
    R/3 says that the transaction is consistent, but at the time that I want to run send the message "User group RHCYA has not yet been created"
    The user group is created, what's wrong???
    Thanks
    Omar

    Hi Omar,
    Please try to Use the User group as "RHCYA1". For some reason, it doesn't take the user group as it is and we need to append some character to the user group at the end. Not sure why it does so. Please use RHCYA1 and see if it works. Hope this helps. Thanks
    Hari

  • Can we create range variable for Query Key Date

    Hello Gurus,
    Can we create a range variable for Query Key Date ? when I tried to give a range of values for Query Key Date, I am unable to find Range Values option. I found only Single Values.
    so, Please let me know if we can use Range variables for Query Key Date ??
    Thanks in advance,
    Regards,
    Aarthi

    Hi Aarthi,
    This is relevant for the time dependant master data that is being pulled in thw query. Like if you are using a nav attr in the query and this nav attr is time dependant, then which record (from the char master data) is to be pulled into the report, depends upon the key date that you specify.
    The default key date value is the date on which the query is executed, that is <Today>.
    Hope this helps...

  • Explain plan for query

    HI all
    Please help to evaluate the explian plan for query suppose the following is the plan
    | Id  | Operation                        | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                 |                  |     7 |  1260 |   303   (1)| 00:00:04 |
    |   1 |  SORT ORDER BY                   |                  |     7 |  1260 |   303   (1)| 00:00:04 |
    |*  2 |   FILTER                         |                  |       |       |            |          |
    |   3 |    NESTED LOOPS                  |                  |       |       |            |          |
    |   4 |     NESTED LOOPS                 |                  |     7 |  1260 |   302   (1)| 00:00:04 |
    |   5 |      NESTED LOOPS                |                  |     7 |   791 |   281   (1)| 00:00:04 |
    PLAN_TABLE_OUTPUT                                                                                      
    |*  6 |       TABLE ACCESS BY INDEX ROWID| TASKDETAIL       |     7 |   574 |   267   (1)| 00:00:04 |
    |*  7 |        INDEX SKIP SCAN           | IDX_TD_TTS       |  2726 |       |    29   (0)| 00:00:01 |
    |*  8 |       TABLE ACCESS BY INDEX ROWID| ORDERS           |     1 |    31 |     2   (0)| 00:00:01 |
    |*  9 |        INDEX UNIQUE SCAN         | PK_SYS_C004711   |     1 |       |     1   (0)| 00:00:01 |
    |* 10 |      INDEX RANGE SCAN            | TEPS_PICK_INDEX1 |     1 |       |     2   (0)| 00:00:01 |
    |* 11 |     TABLE ACCESS BY INDEX ROWID  | TASK_PICK_EPS    |     1 |    67 |     3   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------------------1. what are the columns rows ,bytes,cost ,time indicate us

    The current 11.2 version of the documentation (URL below) would be better than the 9.2 version
    http://docs.oracle.com/cd/E11882_01/server.112/e16638/ex_plan.htm#i19260
    "Rows" is the expected number of rows that will be returned by that step of the plan
    "Bytes" is the expected size of the result set returned by that step of the plan
    "Time" is the expected execution time --- this can be grossly off because Oracle uses some assumptions about singe block read time, multiblock read time and CPU speed.
    Hemant K Chitale
    Edited by: Hemant K Chitale on Sep 25, 2012 3:04 PM

  • No data Found for Query with hierarchy in 2004S SP10 in JAVA Stack

    Hello,
    I have typical issue while running the simple query in ABAP Web and JAVA Web (RSRT) with One row and one column. The char in the row is restricted with external hierarchy.
    If I run in ABAP web, I get the results.
    If I run in JAVA Web, No data found message displayed.
    Does any one come across this issue. Tried to get SAP note but not clear solution.
    If any one give me information where I can find the values used for query variable in the dictionary tables I might help in my investigation.
    Advanced thanks.
    Ramana

    Hello,
    Sorry I missed a point.
    The char on which the hierarchy is resferencing char. Effectively using the hierarchy of referenced char.
    Thanks.

Maybe you are looking for

  • JavaScript Console Problem (only in LS preview mode)

    Hello, my JavaScript console "crashes" in preview-mode in lifecycle designer. It just appears for a "millisecond"´, well I see it flicker at last. It doesn't matter if there is a syntax error or if I try to start the console by clicking a button ( Ev

  • Lost thumbnails in iphoto 6.0.6

    I am copying this post by another person; it is exactly what has happened to me. I tried to do what TD suggested without any results. Is TD referring to the resizing indicator of the library window? I don't see any "+" on the left side of the window.

  • Picture quality when burning disc

    When i burn a slideshow and view it on a tv the picture becomes very bright just before it move to the next slide. Any suggestions?

  • What versions will work with Windows ME?

    I currently have Firefox 1.something on my aging Windows ME system. My e-mail provider recently upgraded and consequently, I need to be using at least verion 2.0 of Firefox. I downloaded the newest version, but get an error after the files have been

  • One asset value to be transferred into different new asset codes

    Hello, I have one asset which has to be transferred into different new asset values. The instance as below: Old Asset: 1000 Value: Rs. 10000 Transferred into New asset code: 1100 Value: Rs. 3000 New Asset: 1200 Value: Rs. 2000 New Asset: 1300 Value: