Get query into a variable

Hi,
See attached code.
Now, when you would run this query (and if you've turned your
CF debugger on), you would see the following in your browser under
your SQL Queries section:
select id_product, product_name
from tbl_product
where id_supplier in (1,2,3)
and is_ordered_by = 'Telephone'
In other words you can see what the query has processed
exactly.
Now, this is just a simple query that I took as an example.
What I want to do is NOT to execute the CFQUERY.
Instead, I want to store the processed part of the query i.e.
select id_product, product_name
from tbl_product
where id_supplier in (1,2,3)
and is_ordered_by = 'Telephone'
into a variable.
Is this possible?
I've tried doing the following:
<cfset querypart = "select id_product, product_name from
tbl_product where id_supplier in (" & variables.supplierIDs
& ") " & <CFIF variables.isElectronic eq 1>"and
is_ordered_by = 'Electronic'"<CFELSE>"and is_ordered_by =
'Telephone'"</CFIF>>
But it's giving me an error "<".
It's as if it can't process the <CFIF> inside the
<cfset>
Please advise.
Thanks and regards,
Yogesh Mahadnac

You could set a session variable to the results of your
query, then use that session variable as if it were a query:
<!--- Query products --->
<cfquery name="qProduct" datasource="db1">
select id_product, product_name
from tbl_product
where id_supplier in (#variables.supplierIDs#)
<cfif variables.isElectronic eq 1>
and is_ordered_by = 'Electronic'
<cfelse>
and is_ordered_by = 'Telephone'
</cfif>
</cfquery>
<!--- set session variable equal to query results --->
<cfset session.querypart = qProduct>
<!--- now list your "query" results using your session
variable--->
<cfoutput query="session.querypart ">
#id_product# #product_name# <br>
</cfoutput>
Of course, once you use your results, you should set your
session variable to NULL to clear the query.
<cfset session.querypart = "">
<edit> I believe that I misread your post, and thought
that you wanted to store the result of your query, not the query
itself.</edit>
Phil

Similar Messages

  • How to use Min function to get FileName into a Variable

    I was wondering how to use MIN function in Evaluate variable in package to get the first file name from the list(Datastore)
    With reference to Merging Flat Files into a single file Post number-4
    Thanx

    Hi Diwakar,
    That List data store should be table, than only it will gives the min of the filename string,
    If it is a file datastore, Min function does not works properly it will returns a first name in the file data store.
    so please, use an interface to upload the List filedatastore into some other temp table. From that table you can use variable to get Min value of file name.
    Thanks
    Madha

  • Stupid question: getting sysdate into repository variable (11g)

    Hi, I'm having a complete brain fade and can't figure out how to select current sysdate into a dynamic repository variable. I've done the following:
    1. Created init block
    2. Set data source to the connection pool from one of my Oracle databases
    3. Set the default database string to "select trunc(sysdate) from dual"
    4. Created a dynamic variable STP_TODAY with default initializer of DATE '1900-01-01'
    5. Check in and save the RPD
    When I go into answers, I can see the variable, but it's always getting the 1900-01-01 date. Obviously I'm doing something dumb - can someone help?
    Thanks!
    Scott

    This is related to presentation server Cache.
    Bypass the Presentation server Cache with the following steps:
    1. In Answers go to Advanced tab and select the "Bypass Oracle BI Presentation Services Cache" box for the report.
    2. At the lower end of the page, you have a box name "prefix", add the below text in it,
    "SET VARIABLE DISABLE_CACHE_HIT=1;"
    3. Save the report.
    Check now, this hopefully should help..
    Regards,
    Kiran

  • Input result from a SQL-query into a Variable in ProcessFlow

    I am trying to select a value from a table with file names.
    This file name should be input to an ftp function. I use a owb function to read the file name then I try to asign the result to a variable.
    The function GET_FILENAME looks like
    f_name varchar2(30);
    BEGIN
    select distinct FILENAME_SOURCE into f_name from CTL_SOURCE_FILES
    where FILEID = (select min(FILEID) from CTL_SOURCE_FILES where status is null);
    RETURN f_name;
    END;
    When running it as a SQL-script it returns only one row/name.
    When I am running it in the ProcessFlow the following message is found:
    RPE-02040: Internal error: GET_FILENAME cannot be converted to a constant value.

    Let me talk about this in context of a mapping:
    create a mapping :
    use a function within a mapping
    assign the output of the mapping to a mapping input variable"
    use this mapping within your process flow and see if it works.
    if you are directly going to use the output of a function in a process flow , the FTP should be able to accept the filename from the outparam of the function which i am not sure how it works.
    try using the first approach as it is relatively simple and straightforward.

  • How to execute a select query stored in variable

    Hello  helpers ,
    I have some "select queries" stored in the database . Now I can derive this query in some variable . How do I execute this query from the variable .
    example :
    Data Query type char50 .
    QueryVar = 'Select MATNR from MBEW where BWKEY = '0001' . '
    How do I execute this Query stoored in variable QueryVar in ABAP program ?
    Thanks a lot for helping .
    Regards
    Shashank

    Shashank,
    It is also possible to use (column_syntax) and (dbtab_syntax) together with (cond_syntax) when using SELECT statements in ABAP. For more info on (column_syntax) and (dbtab_syntax) just have a quick look at ABAP Keyword documention on SELECT statement (hit F1 on SELECT then scroll down to Select->Select result->Select Columns....)
    So in your case, you need to separate out (split) the value in 'wa_itab-query' into other variables or append into separate internal tables using common keys etc. - then looping at those tables with the common key (READ TABLE WITH KEY....) use the following syntax at the time of triggering the SELECT query:
    SELECT (column_syntax)
           FROM (dbtab_syntax)
           WHERE (cond_syntax).
    Also worth a look at this example below:
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
                p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
             fldate TYPE sflight-fldate,
             carrname TYPE scarr-carrname,
             connid   TYPE spfli-connid,
           END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
                   WITH UNIQUE KEY fldate carrname connid.
    DATA: column_syntax TYPE string,
          dbtab_syntax TYPE string.
    column_syntax = `c~carrname p~connid f~fldate`.
    dbtab_syntax = `( ( scarr AS c `
      & ` INNER JOIN spfli AS p ON p~carrid  = c~carrid`
      & ` AND p~cityfrom = p_cityfr`
      & ` AND p~cityto   = p_cityto )`
      & ` INNER JOIN sflight AS f ON f~carrid = p~carrid `
      & ` AND f~connid = p~connid )`.
    SELECT (column_syntax)
           FROM (dbtab_syntax)
           INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT itab INTO wa.
      WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Hope this helps.
    Cheers,
    Sougata.

  • Recordset into a variable

    Sorry for the newbie question. How can I stick the results of a query into a variable?
    And in results I mean the entire row, not just one value.

    SQL> set serveroutput on;
    SQL> begin
      2    for emp_rec in (select * from emp) loop
      3      dbms_output.put_line(emp_rec.ename||','||emp_rec.job);
      4    end loop;
      5  end;
      6  /
    JONES,MANAGER
    FORD,ANALYST
    KING,PRESIDENT
    BLAKE,MANAGER
    CLARK,MANAGER
    SMITH,CLERK
    ALLEN,SALESMAN
    WARD,SALESMAN
    MARTIN,SALESMAN
    SCOTT,ANALYST
    TURNER,SALESMAN
    ADAMS,CLERK
    JAMES,CLERK
    MILLER,CLERK
    PL/SQL procedure successfully completed.
    SQL>

  • Can I put a SQL query into a bind variable and then use it to output report

    Hi,
    Can I put a SQL query into a bind variable and then use it to output report?
    I want to create a report and an item "text area" (say P1_TEXT) which can let user to input a SQL query(they are all technical users and knows SQL very well). Then, I use a bind variable (that text area) to store the SQL statement. Then, I add a submit button and I want to use the following to output the report:
    select * from (:P1_TEXT);
    Do you think it is possible to do that? Any known limitations for APEX in this area?
    Thanks a lot,
    Angela

    You can, but make sure it's what you really want to do. Make sure you are VERY familiar with SQL Injection. Most people who know what it is, go out of their way to prevent SQL Injection. You're going out of your way to allow it.
    You can try using &P1_TEXT. instead of bind variable syntax. Bind variables are one of the best ways to prevent SQL Injection, which is why it's not working for you.
    Once again, I strongly urge you to consider the implications of your app, but this suggestion should get it working.
    Tyler

  • Mapping proc output to vars gets error extracting result into a variable of type (DBTYPE_UI2)

    Hi, we run std 2012.  I have a proc (sets nocount on) whose params r shown in the first block .   My execute ssis sql task mapping is shown in the block following that (same order as shown, the param sizes are all -1).  The variable
    characteristics and initial values are shown in the 3rd block.  The execute sql task command is
    exec usp_fileArrivalStatus ?,?,?,?,?,? output,? output,? output
    when I run the proc in ssms followed by a select on the output fields, I get stat 0, instance id -1 and file name empty string (aka tick tick aka '')
    The error is:
    [Execute SQL Task] Error: Executing the query "exec usp_fileArrivalStatus ?,?,?,?,?,? output,? ou..." failed with the following error:
    "An error occurred while extracting the result into a variable of type (DBTYPE_UI2)".
    Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Does anybody know what is wrong?
    CREATE PROCEDURE [dbo].[usp_fileArrivalStatus] @NewFilePattern varchar(500),
    @PkgName varchar (257),
    @appid int,
    @MsgHistCreateDate date,
    @messageFriendlyName varchar(500),
    @arrivalStatus int output,
    @instanceId bigint output,
    @fileName varchar(500) output
    VariableName Direction DataType ParamName
    User::TranFilePattern Input VARCHAR 0
    System::PackageName Input VARCHAR 1
    User::AppID Input SHORT 2
    User::todaysDate Input DATE 3
    User::TranFileArriveStatus OUTPUT SHORT 5
    User::TranFileInstanceId OUTPUT LARGE_INTEGER 6
    User::TranFileName OUTPUT VARCHAR 7
    User::TranFileFriendlyName Input VARCHAR 4
    User::TranFilePattern,string,tranfile05-Nov-2014
    User::fileDate,string,05-Nov-2014
    System::PackageName,
    User::AppID,int32,12
    User::todaysDate,DateTime, set by select getdate()
    User::TranFileArriveStatus,int32,0
    User::TranFileInstanceId,Int64,0
    User::TranFileName,string
    User::TranFileFriendlyName,string,Tran File

    I may have gotten past this.  The ui showed the first execution of that proc as the aborting component but when I looked at my error code (-1073548784), and component name in the
    message sent with notification email, I noticed the second component name.  It too executes that proc and still had ushort for appid in sql task mapping and long for instance id.  I changed these characteristics to match what I posted and got green
    on the seq container that runs both.
    I think I go thru this kind of adventure every time I try to map proc output to ssis vars.   

  • Reg:Getting error text from a channel into a file or into a variable

    Hi,
    Can we get the error text such as u201Cjava.lang.NegativeArraySizeExceptionu201D  from a communication channel into a variable or in the form of an xml message so that based on kind of error further processing can be done.
    Regards,
    Rahul

    You can decide further processing based on the data available in the mapping. If the value comes in the source field for a list element as you expected do UDF and return error as string and decide the mapping as per business need. I talk about something like enhanced interface determination. That's one way. Reading the error message from the communication channel and decide does not seem to be better option.

  • Question when I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    Question
    when I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    See this. <br />
    https://support.mozilla.com/en-US/kb/Firefox+hangs#Hang_at_exit

  • When I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    Question
    When I log into Firefox, the screen scrolls down and I have to use the side-bar to go back up to type my query into the 'search' window. How can I stop that and get Firefox to start with the 'search' window accessible? With thanks, Peter

    See this. <br />
    https://support.mozilla.com/en-US/kb/Firefox+hangs#Hang_at_exit

  • How get Query Monitor (RSRT1) to show variable input screen

    Hi,
    I'm trying to test a query that has variable input and I can't get the variable input screen to give me a chance to input variables.  Since this is key to debugging this query, I need it to recognize my input variables.
    Help!
    Thanks
    Suzanne

    Hi,
    In rsrt, enter the query name -> select query display as HTML -> In the big text box that appears below it type "variable_screen=x", without quotes and it should show you the variable screen.
    Thanks,
    Sri.

  • How do I get sdo_point into C host variables from OTT structures?

    How do I get sdo_point info into C host variables from structures generated by OTT?
    Databse Version 10.1.0
    I am using OTT to generate C structures for the Oracle Spatial datatype sdo_geometry. The file is generated as
    #ifndef GEOMETRY_ORACLE
    # define GEOMETRY_ORACLE
    #ifndef OCI_ORACLE
    # include <oci.h>
    #endif
    typedef OCIRef sdo_geometry_ref;
    typedef OCIRef sdo_point_type_ref;
    typedef OCIArray sdo_elem_info_array;
    typedef OCIArray sdo_ordinate_array;
    struct sdo_point_type
    OCINumber x;
    OCINumber y;
    OCINumber z;
    typedef struct sdo_point_type sdo_point_type;
    struct sdo_point_type_ind
    OCIInd _atomic;
    OCIInd x;
    OCIInd y;
    OCIInd z;
    typedef struct sdo_point_type_ind sdo_point_type_ind;
    struct sdo_geometry
    OCINumber sdo_gtype;
    OCINumber sdo_srid;
    struct sdo_point_type sdo_point;
    sdo_elem_info_array * sdo_elem_info;
    sdo_ordinate_array * sdo_ordinates;
    typedef struct sdo_geometry sdo_geometry;
    struct sdo_geometry_ind
    OCIInd _atomic;
    OCIInd sdo_gtype;
    OCIInd sdo_srid;
    struct sdo_point_type_ind sdo_point;
    OCIInd sdo_elem_info;
    OCIInd sdo_ordinates;
    typedef struct sdo_geometry_ind sdo_geometry_ind;
    #endif
    I can successfully access the sdo_gtype and sdo_ordinates using the following ProC code
    exec sql begin declare section;
    int sptype;
    double coord[100000];
    sdo_geometry *spgeom;
    sdo_ordinate_array *spcoords;
    exec sql end declare section;
    /* allocate memory for the geometry host variable */
    exec sql allocate :spgeom;
    select bounds into :spgeom from boundary;
    /* retrieve the geometry type from the geometry host variable into a host variable */
    exec sql object get sdo_gtype from :spgeom into :sptype;
    /* allocate memory for the sdo_ordinate_array host variable */
    exec sql allocate :spcoords;
    /* move the coordinates from the geometry host variable into the sdo_ordinate_array host variable */
    exec sql object get sdo_ordinates from :spgeom into :spcoords;
    /* determine the number of coordinates */
    exec sql collection describe :spcoords get size into :numord;
    /* move the coordinates from the sdo_ordinate_array host variable into a host array */
    exec sql for :numord collection get :spcoords into :coord;
    I cannot, however, figure out how to get point data out of the host variable spgeom. If I prepare code analagous to the other types in the geometry structure, I get an error. I can see that sdo_point is different because it is a struct within the geometry definiton of typedef OCIRef but my knowledge of C is sufficeintly weak that I cannot figure out how to get sdo_point into C host variables. Some sample code for getting the sdo_point data would be greatly appeciated.
    Thanks, Chris

    To get point data from geometry column use following
    select a.location.sdo_point.x, a.geometrycolumn.sdo_point.y
    from tablename a;
    Do not forget to alias the table.

  • How do I get this query into Discoverer Plus

    Hi all,
    I have the following query:
    SELECT h.hrs, NVL(Quantity, 0) Quantity
    FROM (SELECT TRIM(to_char(LEVEL - 1, '00')) hrs
    FROM dual
    CONNECT BY LEVEL < 25) h
    LEFT JOIN (SELECT TO_CHAR(event_date, 'HH24') AS during_hour,
    COUNT(*) Quantity
    FROM user_activity u
    WHERE event_date BETWEEN
    to_date('15-JUN-2010 14:00:00', 'DD-MON-YYYY HH24:MI:SS') AND
    to_date('16-JUN-2010 13:59:59', 'DD-MON-YYYY HH24:MI:SS')
    AND event = 'user.login'
    GROUP BY TO_CHAR(event_date, 'HH24')) t
    ON (h.hrs = t.during_hour)
    ORDER BY h.hrs;
    Which produces the number of actions performed (from an event table, user_activity) grouped by the hour of the day they occurred (including displaying hours that have zero records - this bit is important!). I want to be able to put this into Discoverer plus as a worksheet, but I'm having trouble trying to figure out how.
    I was able to create a custom folder in Administrator for the select from DUAL, but I cannot link it to the user_activity table because there's no relationship between to two tables to create a join.
    The user_activity table is:
    USER_ID - VARCHAR2(8 CHAR)
    EVENT_DATE - DATE
    EVENT - VARCHAR2(100 CHAR)
    The custom folder is this part of the SQL:
    SELECT TRIM(to_char(LEVEL - 1, '00')) hrs FROM dual CONNECT BY LEVEL < 25
    Any suggestions would be greatly appreciated.
    Thanks.
    Edited by: Cyntech on Aug 12, 2010 10:41 AM

    KK wrote:
    hi,
    In the custom folder we can join tables,but the thing is you said ther is no join between them.
    I would suggest you to built this query into a view and use this view in the DUAL table by writing inline query or subquery what ever way.
    This is the only possibility i can think off.
    Hope it helps you.
    By,
    KKHi,
    Thanks for the reply, though I'm not sure that I understand what you are suggesting.
    Which query would you turn into a view? If you are referring to the select from dual, then how would the view be any different from the custom folder? You still would not be able to join it to user_activity as there are no common columns.
    Edited by: Cyntech on Aug 12, 2010 2:49 PM

  • Creating Variable with Replacement Path to get value from ANOTHER Variable

    Hi all,
        Is anyone has created the Variable with Replacement Path to get the value from another User Entry Variable, PLEASE ? 
    First created the User Entry Variable (ZV_X) and it accepts the date range like '01/01/2009 - 01/31/2009'. Next created the Characteristic variable (ZV_Y) of Replacement Path for which source variable will be ZV_X and we should get the 'FROM Date' (01/01/2009) from the selection (ZV_X) into it (ZV_Y).
    While creating the Characteristic variable (ZV_Y) of Replacement Path, I didn't find my newly created ZV_X variable in the list of available variables under 'Variable' header in 'Replacement Path' tab and it is causing the error 'Source to replace variable ZV_Y is not defined'. How could I create the Characteristic variable of Replacement Path for my requirement, PLEASE ?
    The following is from help.sap..com:
    Replace with Characteristic Value
    Text and formula variables with the processing type Replacement Path can be replaced with a corresponding characteristic value. In the variable editor, on the General tab page, you specify under Reference Characteristic the characteristic that is to be referenced by the replacement. On the Replacement Path tab page, you can choose whether the variable is replaced with the From or the To Value and with the Key or the Name of the characteristic value. You can also specify the Offset Start and Offset Length for the output.
    Replace with Variable
    Characteristic value variables, hierarchy variables, text variables, and formula variables with the Replacement Path processing type can take their values from a different variable.
    The following prerequisites need to be fulfilled:
    Variable
    ●      The variable must not be input-ready
    ●      The variable must represent a single value
    Source Variable
    ●      The source variable must not be a hierarchy node variable
    ●      The source variable must be input-ready
    ●      The source variable must be available in the query
    ●      The source variable must represent a single value or an interval
    In the variable editor, on the Replacement Path tab page, you specify the source variable from which the value is to be determined. The value is either determined from the key, the external attribute of the key, the description, or the attribute value. You can specify an Offset Start and an Offset Length for the output here. The variable is replaced on the variable screen upon each data release.
    Thanks,
    Venkat.

    Hi Eve,
    It is possible to connect the 2 queries using a Replacement Path characteristic variable. You would need to create the variable on the char whose values you want to pass from Q1 to Q2. The variable will be of type replacement path and you will need to enter the name of Q1 from which it will get the values. Make sure that you include this char in the query definition of Q1 and Q2. In Q2 you will restrict the characteristic using this variable. DO not use this variable (replacement path) in Q1.
    In your query properties check if you have turned on the checkmark for Release for OLE DB for OLAP (3rd tab). If the check mark is there, then remove it.
    We are using the scenario in a couple of places, and it works very well.
    Hope this helps...

Maybe you are looking for

  • FCPX how many times can it install on the same computer?

    From time to time I like to wipe the drives and start afresh or, whenever there is a new OS, I will perform a clean install. This entails wiping the drive and reloading all software. Most of the apps have 'de-authorize' function, this allows me to us

  • Missing Dynamic Pages and SEO

    Hello I have a details page that takes the URL parameter Product-Code and displays the details for that product. Now what happens when I remove a prduct from the database and that URL still exists in the Search Engine indexes. I noticed that even tho

  • Output of RFC FM in background job

    Hello, I have a report which call an RFC FM. The FM calls a class which write some output using write statement. How can this output be captured in the spool request of job for my report? Is it possible? Regards, Ahmed

  • Dynamic Column Selector in OBIEE - Solution required

    Hello Experts, I am pretty new to OBIEE. Please help me to get OBIEE solution for below requirement. I have one 25 column dimension table in database. Created OBIEE .rpd file and published in BI server. Now I need to provide one user interface in whi

  • INSIGNIA 55 LCD TV

    Hello, I am a Reward Zone Premier Silver Member and I purchase ALL my electronics at Best Buy, I recently purchased this 55 inch LCD Insignia this July 28, 2012, about a month and a half ago I noticed something on the left side of the screen, white g