Dynamic SQL Command Queries Using Parameters

Post Author: tdoman
CA Forum: Data Connectivity and SQL
I'm using Crystal Reports 11 and am trying to dynamically build part of the "Where" clause in the SQL command query to filter data on the server before the results are sent to the client. I'm doing this to decrease the load time of my reports by not having to send a large set of data to the client, then filter the results on the client side.
I want to create a parameter list that is dynamically generated from a table in a database and allows you to select mutiple values from that list. For example: I have two tables. One employee table and one employee type table. The employee table lists all employees and their related employee types (full-time, part-time, and contractor). The employee type table lists the employee types that will dynamically be loaded into the parameters list.
Employee Table
ID    Name       TypeID
1     Bob          2
2     Steve        1
3     John         3
4     Bill            1
Employee Type Table
ID   Type
1     Full-Time
2     Part-Time
3     Contractor
Assuming the user selects u2018Full-Timeu2019 and u2018Contractoru2019 from the parameter list, the SQL command query I want to generate is as follows:
SELECT *
FROM emp, emp_type
WHERE emp.ID = emp_type.ID and emp.TypeID in (u20181u2019, u20183u2019)
I tried building the following SQL command query so it would dynamically replace {?EmpType} with the IDu2019s of the types the user selected but it doesnu2019t work. Any ideas how to fix this?
SELECT *
FROM emp, emp_type
WHERE emp.ID = emp_type.ID and emp.TypeID in ({?EmpType})

Post Author: tdoman
CA Forum: Data Connectivity and SQL
btw...I just realized I had a typo in my "where" clause of the previous example. It should have been like so:WHERE emp.TypeID = emp_type.ID and emp.TypeID in (u20181u2019, u20183u2019)  satish_nair31:
Instead of passing the filter condition as parameter it would be fine if you pass it by ReportViewer.SelectionFormula Property.
The selection formula property of report viewer control will dynamically append the where condition with the SQL value. You will pass the filter condition as per the syntax of language supported by crystal reports.I believe using the ReportViewer.SelectionFormula property you are referring to is only available if I'm loading the report through a VB application. If this is true, then this option will not work for me because I'm loading the report in a browser from the Crystal Report web server and currently don't have a VB application that can load the report. If I did, then I could dynamically build the SQL string using VB then pass it to the Crystal Report on the fly.But I'm trying to figure out if it's possible to do it without loading the report using VB. Please correct me if I'm wrong on these assumptions.

Similar Messages

  • Passing table names as parameters (aka Trouble building a dynamic SQL command)

    I am attempting to develop a template for publishing some data, and would like to pass standard table names as parameters to the various queries.  What I have created generates the following error:
    Msg 137, Level 16, State 1, Procedure spPublishTrans_FlashersCaution, Line 68
    Must declare the scalar variable "@tmpTable".
    I thought I was declaring it properly ?
    Thanks.
    DECLARE @FeatureClass as Nvarchar(MAX) = 'Trans_FlashersCaution'
    DECLARE @ED as Nvarchar(MAX) = 'edgis.dbo.' + @FeatureClass
    DECLARE @tmpTable TABLE
    [OBJECTID] [int] NOT NULL,
    [Id] [int] NULL,
    [Location] [nvarchar](60) NULL,
    [Zone] [nvarchar](5) NULL,
    [Shape] [geometry] NULL
    DECLARE @tmpTableParam AS NVARCHAR (MAX) = @tmpTable
    SELECT @tmpTableParam
    DECLARE @execquery AS NVARCHAR(MAX)
    SET @execquery = 'INSERT INTO' + @tmpTableParam +
    [OBJECTID]
    ,[Id]
    ,[Location]
    ,[Zone]
    ,[Shape]
    SELECT
    [OBJECTID]
    ,[Id]
    ,[Location]
    ,[Zone]
    ,[Shape]
    FROM' + @ED;
    EXECUTE sp_executesql @execquery

    Always PRINT the SQL string prior to execution when developing dynamic SQL script:
    PRINT @execquery
    --EXECUTE sp_executesql @execquery
    Second step, test the printed SQL script for validity.
    Dynamic SQL: http://www.sqlusa.com/bestpractices/dynamicsql/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • How to pass SQL command parameter using OpenDocument

    Hi !
    I have a dynamic List of values configured in Business View manager, used across multiple reports.
    The data source for this LOV is a SQL Command which accepts a static parameter named stringParam. I need to pass this static parameter in the URL using OpenDocument command. How can I do this?
    I tried
    http://bobjdev/businessobjects/enterprise115/InfoView/scripts/opendocument.aspx?spath=[ReportFolder]&sDocName=WebReport.rpt&stype=rpt&lsSstringParam=ABC
    but it still prompts me to select the parameter. I need to avoid this prompt.
    Any help, please.

    Hi,
    I would recommend to take a look at the documentation in order to identify the correct syntax for your URL
    [http://help.sap.com/businessobject/product_guides/boexir31/en/xi3-1_url_reporting_opendocument_en.pdf]
    Regards,
    Shweta

  • SQL Command and Datetime Parameters

    <p>Hi, </p><p>I am having problems  adding datetime parameters to a SQL command.</p><p>The code is AND table.startdatetime >= &#39;{?start}&#39; </p><p>I enter the time and date in the parameter and get the following error.<br /><br /><strong>Incorrect syntax near 2006</strong></p><p>Any clues</p><p>Thanks</p>

    Hi,
    What database you are using?
    Regards
    Sarobinyal

  • Crystal report SQL Command and using IN

    Post Author: geozuh
    CA Forum: Crystal Reports
    Does any one know how to get a multiple value prompts to work in Crystal report SQL Commands? I have an extremely large database and do not want to pull back all the records to the report. I know I can do the filtering in the report, but due to the size of the database, I am restricked from doing do.
    I would like to set the State as a multiple value parameter/prompt to be used in the SQL Command.
    Ex.
    Select CustID, FirstName, LastName
    from Customer
    where State in ('WI', 'IL', 'MN') --this would be turned into a parameter

    Post Author: yangster
    CA Forum: Crystal Reports
    you are over thinking the problemsimply create a parameter within crystal for your state and change it to allow multiple valuesthen in the select expert put in state = ?stateif you do show sql query you will see that the values are pushed down to the sql level thus no performance hit vs putting the parameter directly in the command itself

  • An issue with Dynamic SQL within Package using REF CURSOR

    Hi there,
    In the following package first two procedures works file but since I have added the third one ( GET_CONTRACT_BY_DYN_SQL) it does not work for me. When I try to compile and save it gives below error.
    "Error(6,15): PLS-00323: subprogram or cursor 'GET_CONTRACT_BY_DYN_SQL' is declared in a package specification and must be defined in the package body"
    Can you please help?
    Package Header
    create or replace
    PACKAGE CONTRACTS_PKG AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE GET_CONRACTS (IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_ID (I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRATID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR);
    END CONTRACTS_PKG;
    Package Body
    create or replace
    PACKAGE BODY CONTRACTS_PKG AS
    -- Get All Contracts
    PROCEDURE GET_CONRACTS(IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS;
    IO_CURSOR := V_CURSOR;
    END GET_CONRACTS;
    -- Get Contract By ID
    PROCEDURE GET_CONTRACT_BY_ID(I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS WHERE contract_id = I_CONTRACTID;
    IO_CURSOR := V_CURSOR;
    END GET_CONTRACT_BY_ID;
    -- Get Contract Using Dynamic SQL
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRACTID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    V_SQL VARCHAR2(200);
    BEGIN
    V_SQL := 'SELECT '|| P_COLS || ' FROM CONTRACTS WHERE contract_id = ' || P_CONTRACTID ;
    --OPEN V_CURSOR FOR
    --EXECUTE IMMEDIATE V_SQL INTO V_CURSOR;
    OPEN V_CURSOR FOR V_SQL;
    EXECUTE IMMEDIATE V_SQL;
    --IO_CURSOR := V_CURSOR;    
    END GET_CONTRACT_BY_DYN_SQL;
    END CONTRACTS_PKG;
    Thanks in advance.
    Hitesh

    Thanks guys. Finally I have tweaked as per your suggestions and it's working for all 3 cases (stored procedures).
    Oracle
    ======
    Package Header
    create or replace
    PACKAGE CONTRACTS_PKG AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE GET_CONRACTS (IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_ID (I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRACTID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR);
    END CONTRACTS_PKG;
    Package Body
    create or replace
    PACKAGE BODY CONTRACTS_PKG AS
    -- Get All Contracts
    PROCEDURE GET_CONRACTS(IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS;
    IO_CURSOR := V_CURSOR;
    END GET_CONRACTS;
    -- Get Contract By ID
    PROCEDURE GET_CONTRACT_BY_ID(I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS WHERE contract_id = I_CONTRACTID;
    IO_CURSOR := V_CURSOR;
    END GET_CONTRACT_BY_ID;
    -- Get Contract Using Dynamic SQL
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRACTID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    V_SQL VARCHAR2(200);
    BEGIN
    IF p_contractid > 0 THEN
    V_SQL := 'SELECT '|| P_COLS || ' FROM CONTRACTS WHERE contract_id = ' || P_CONTRACTID ;
    ELSE
    V_SQL := 'SELECT '|| P_COLS || ' FROM CONTRACTS';
    END IF;
    OPEN V_CURSOR FOR V_SQL;
    IO_CURSOR := V_CURSOR;
    END GET_CONTRACT_BY_DYN_SQL;
    END CONTRACTS_PKG;
    ColdFusion (calling app code)
    =====================
    <cfstoredproc procedure="CONTRACTS_PKG.GET_CONTRACT_BY_ID" datasource="#REQUEST.dsn#">
         <cfprocparam cfsqltype="CF_SQL_INTEGER" type="in" value="1" variable="I_CONTRACTID">
         <cfprocresult name="qData" resultset="1">
    </cfstoredproc>
    <br>Single Contract:
    <cfdump var="#qData#" label="Single Contract">
    <cfstoredproc procedure="CONTRACTS_PKG.GET_CONRACTS" datasource="#REQUEST.dsn#">     
         <cfprocresult name="qDataAll" resultset="1">
    </cfstoredproc>
    <br>All Contracts:
    <cfdump var="#qDataAll#" label="All Contracts">
    <cfstoredproc procedure="CONTRACTS_PKG.GET_CONTRACT_BY_DYN_SQL" datasource="#REQUEST.dsn#">
         <cfprocparam cfsqltype="CF_SQL_INTEGER" type="in" value="1" variable="P_CONTRACTID">
         <cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="contract_number,contract_title,created_date" variable="P_COLS">
         <cfprocresult name="qDataDynSQL" resultset="1">
    </cfstoredproc>
    <br>Dynamic SQL Query:
    <cfdump var="#qDataDynSQL#" label="Dynamic SQL Query">
    Thanks,
    Hitesh Patel

  • Using NVL function in Dynamic SQL

    Hi ,
    I have created a procedure using the Dynamic SqL and while using the NVL() getting the following error . ORA-00936: missing expression.
    The query I have written as
    SQL_Txt:=' INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
         SELECT '||l_A||',
         '||l_B||',
         '||l_C||',
              '||l_D||',
              NULL ,
              '||L_F||',
              NVL('||Param1||',''''),
              NVL('||Param2||',''''),
              NVL('||Param3||',''''),
              NULL
              FROM '||ParamTbl1||' WHERE ' ;
    and so on.
    For Param1 I have data for one execution and Param2 and Param3 is null for that execution.
    While executing the same I am getting below
    INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
    SELECT 25,
         1,
         7,
              6,
              NULL ,
              5,
              NVL(PurchaseDate,''),
              NVL(,''),
              NVL(,''),
              NULL
              FROM xyz.PBuyer@pocdb WHERE
    and error ORA-00936: missing expression is popping up for Param2 and Param3 NVL(,'')
    Any suggestion to resolve this issue is highly appreciable.
    Thanks
    Sudipta

    NVL(,''),Where's the first argument to NVL? That's the obvious problem. Empty strings are NULL in Oracle anyway, so just lose the NVL and insert the values...
    C:\>                                                                        
    C:\>sqlplus hr/hr                                                           
    SQL*Plus: Release 11.2.0.3.0 Production on Wed May 8 10:08:53 2013          
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.                     
    Connected to:                                                               
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set NULL I_AM_NULL                                                     
    SQL> create table x(y varchar2(20));                                        
    Table created.                                                              
    SQL> insert into x values ('');                                             
    1 row created.                                                              
    SQL> select * from x;                                                       
    Y                                                                           
    I_AM_NULL                                                                   
    SQL>                                                                        

  • Question on Dynamic SQL Execution

    Hi,
    Our company is currently using Oracle 7 but will move to Oracle 8i soon. I am trying to execute a dynamic SQL statement in a function and it always error-out during execution. The SQL statement is NOT doing any update to a table. Its doing a select only. The function is being called during an execution of another dynamic SQL statement in a procedure. Here are examples of the code listing for the procedure and function:
    CREATE OR REPLACE PROCEDURE TEST_PROC
    lookup_cursor      integer;
    ignore          integer;
    VARvalue          number;
    begin
    lookup_cursor := DBMS_SQL.open_cursor;
    DBMS_SQL.PARSE( lookup_cursor,
              'SELECT ' || TEST_FUNCTION || ' FROM DUAL,
              DBMS_SQL.NATIVE);
    DBMS_SQL.DEFINE_COLUMN( lookup_cursor, 1, VARvalue);
    ignore := DBMS_SQL.EXECUTE(lookup_cursor);
    loop
         IF DBMS_SQL.FETCH_ROWS(lookup_cursor) > 0 THEN
         DBMS_SQL.COLUMN_VALUE(lookup_cursor, 1, VARvalue);
         ELSE
         EXIT;
         END IF;
    END LOOP;
    DBMS_SQL.CLOSE_CURSOR(lookup_cursor);
    end TEST_PROC;
    CREATE OR REPLACE PROCEDURE TEST_FUNCTION
    lookup_cursor      integer;
    ignore          integer;
    VARvalue          number;
    VARsql_string     VARCHAR2(200);
    begin
    lookup_cursor := DBMS_SQL.open_cursor;
    VARsql_string := SOME GENERATED SQL STATEMENT;
    DBMS_SQL.PARSE( lookup_cursor,
              VARsql_string,
              DBMS_SQL.NATIVE);
    DBMS_SQL.DEFINE_COLUMN( lookup_cursor, 1, VARvalue);
    ignore := DBMS_SQL.EXECUTE(lookup_cursor);
    loop
         IF DBMS_SQL.FETCH_ROWS(lookup_cursor) > 0 THEN
         DBMS_SQL.COLUMN_VALUE(lookup_cursor, 1, VARvalue);
         ELSE
         EXIT;
         END IF;
    END LOOP;
    RETURN VARvalue;
    end TEST_FUNCTION;
    The error I received during execution of TEST_PROC is:
    ORA-06571: Function TEST_FUNCTION does not guarantee not to update database
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 239
    ORA-06512: at "SYS.DBMS_SQL", line 32
    It may seem like the example procedure doesnt need to use a dynamic SQL execution to call TEST_FUNCTION but the actual code that I extracted from does.
    Does Oracle 7 always treat the dynamic SQL command set as some kind of update statement? Is that a bug? I understand that the EXECUTE IMMEDIATE command in Oracle 8i will replace the old command set found in the above examples. Will using the new EXECUTE IMMEDIATE command in Oracle 8i solve this problem?
    Thank you for any help,
    Tony

    In Oracle 7, for a function to be called from a select statement it has to follow the 'purity rule' that it does not modify any database table or package variable.
    Probably you will have to use the compiler directive PRAGMA RESTRICT_REFERENCES (WNDS,WNPS) on your TEST_FUNCTION so that it can be called within a SQL statement.
    This restriction is removed in Oracle 8i onwards.
    Hope this solves your problem.
    Regards

  • FLASHBACK Database : rman vs sql command differnces

    I am new to Oracle and want understand the difference and which is the correct way of flashing back the database?
    RMAN command vs SQL Command on using FLASHBACK DATABASE
    SQL> FLASHBACK DATABASE TO RESTORE POINT BEFORE_ONLINE_TEST;  {CODE} Vs rman> run{
         flashback database to restore point BEFORE_TEST_320130313;
         sql "alter database open resetlogs"; }
    Referring this article on http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmflash.htm#BGBDCAFA it says we can use both RMAN and SQL command for database flashback.
    Questions:
    1. Difference between using RMAN and SQL command on database flashback?
    2. When to use RMAN or SQL on the  database flashback?
    3. Which is the Oracle recommended or best way ?
    Edited by: Sivaprasad S on Mar 15, 2013 7:26 PM
    Edited by: Sivaprasad S on Mar 15, 2013 7:26 PM
    Edited by: Sivaprasad S on Mar 15, 2013 7:27 PM
    Edited by: Sivaprasad S on Mar 15, 2013 7:27 PM
    Edited by: Sivaprasad S on Mar 15, 2013 7:28 PM
    Edited by: Sivaprasad S on Mar 15, 2013 7:29 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    When I issue the SQL Plus command of
    SQL> flashback database to restore point BEFORE_TEST_20130313 ;
    flashback database to restore point BEFORE_TEST_20130313
    ERROR at line 1:
    ORA-38754: FLASHBACK DATABASE not started; required redo log is not available
    ORA-38762: redo logs needed for SCN 87612483975 to SCN 87612485856
    ORA-38761: redo log sequence 1 in thread 1, incarnation 3 could not be accessedHowever on running this on RMAN
    RMAN>
    list backup of archivelog scn between 87612483975 and 87612485856
    RMAN> ;
    starting full resync of recovery catalog
    full resync complete
    List of Backup Sets
    ===================
    BS Key  Size       Device Type Elapsed Time Completion Time
    5212758 19.75M     SBT_TAPE    00:00:04     13-MAR-2013 16:36:17
            BP Key: 5212765   Status: AVAILABLE  Compressed: NO  Tag: TAG20130313T163611
            Handle: <TestDB_60:809973373:1>.al   Media: 945c30b6:506c6cd2:3a14:0001
      List of Archived Logs in backup set 5212758
      Thrd Seq     Low SCN    Low Time             Next SCN   Next Time
      1    1       87612468290 13-MAR-2013 13:28:19 87612484321 13-MAR-2013 16:36:06
      1    2       87612484321 13-MAR-2013 16:36:06 87612484339 13-MAR-2013 16:36:09
    BS Key  Size       Device Type Elapsed Time Completion Time
    5212759 896.50M    SBT_TAPE    00:00:17     13-MAR-2013 16:36:30
            BP Key: 5212766   Status: AVAILABLE  Compressed: NO  Tag: TAG20130313T163611
            Handle: <TestDB_59:809973373:1>.al   Media: 945c30b6:506c6cbd:39f5:0001
      List of Archived Logs in backup set 5212759
      Thrd Seq     Low SCN    Low Time             Next SCN   Next Time
      1    5       87612363812 12-MAR-2013 14:22:26 87612659040 13-MAR-2013 03:04:08
    run {
    allocate CHANNEL dev_2  TYPE 'SBT_TAPE' format '%U' PARMS  'SBT_LIBRARY=/opt/omni/lib/libob2oracle8_64bit.so,ENV=(OB2BARTYPE=Oracle8)';
    allocate CHANNEL dev_3  TYPE 'SBT_TAPE' format '%U' PARMS  'SBT_LIBRARY=/opt/omni/lib/libob2oracle8_64bit.so,ENV=(OB2BARTYPE=Oracle8)';
    allocate CHANNEL dev_4  TYPE 'SBT_TAPE' format '%U' PARMS  'SBT_LIBRARY=/opt/omni/lib/libob2oracle8_64bit.so,ENV=(OB2BARTYPE=Oracle8)';
    flashback database to restore point BEFORE_TEST_20130313;
    sql "alter database open resetlogs";
    release channel dev_2;
    release channel dev_3;
    release channel dev_4;
    starting media recovery
    archived log for thread 1 with sequence 2 is already on disk as file +DG_PERF_FLASH_02/TestDB/archivelog/2013_03_14/thread_1_seq_2.3612.810054205
    archived log for thread 1 with sequence 3 is already on disk as file +DG_PERF_FLASH_02/TestDB/archivelog/2013_03_14/thread_1_seq_3.1588.810054205
    channel dev_2: starting archived log restore to default destination
    channel dev_2: restoring archived log
    archived log thread=1 sequence=1
    channel dev_2: reading from backup piece <TestDB_60:809973373:1>.al
    channel dev_2: piece handle=<TestDB_60:809973373:1>.al tag=TAG20130313T163611
    channel dev_2: restored backup piece 1
    channel dev_2: restore complete, elapsed time: 00:00:46
    channel dev_2: deleting archived log(s)
    archived log file name=+DG_PERF_FLASH_02/TestDB/archivelog/2013_03_15/thread_1_seq_1.2969.810106317 RECID=49 STAMP=810106318
    media recovery complete, elapsed time: 00:00:05
    Finished flashback at 10-MAR-2013 05:32:07
    database reset to incarnation 5215723
    When we issue the SQL Plus command, if there is  need of old database backup of archive log, how does that SQL Plus communicate with rman recovery catalog and retrieve?

  • SQL Command for searching

    I have a database with fields containing large amounts of text. I wish to be able to search the text in the database using a sql command. I have a number of problems:
    1. I will not know in advance how many words the user will be searching for eg 'Holidays' or 'Holidays in England' so how can I split these up and search effectively?
    2. What is the SQL command to use to check in the database field to see if it has any of the related strings?
    Any help would be greatly appreciated.

    1.Use StringTokenizer to split the words in your search string
    StringTokenizer st = new StringTokenizer("query_string"," ");
    2.Suppose it has 2 tokens then, construct a query like this, (You can use st.countTokens() to get the token count)
    Select * from table where col1 like '%token1%' or col1 like '%token2%'
    Hope this helps.
    Sudha

  • SQL Command Dynamic Parameters

    I have several reports which run on SQL commands.  I created a number of parameters and inserted them into the Command.  When I then modify the parameters to be 'dynamic', I get 2 sets of prompts.
    I'm told this is a bug in XI.  I'm using Crystal reports 2008.  Does anybody know if there is a fix for this bug?

    Use a separate Command to pull your LoVs (make sure that it's doesn't require any parameters). There should be no need to link the LoV Command to your main data Command... Just make sure you aren't placing any of the LoV fields on the report.
    HTH,
    Jason

  • Can I use multiline SQL commands in a query (within a component)?

    I would like to modify the following query:
    <td>ItranslationString</td>
         <td>
         INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (?, ?, ?, 'N', ?)
         </td>
         <td>daKeyField varchar
         daLanguageField varchar
         daTranslationField varchar
         StringTranslationFilename varchar
         </td>
    so that the daSourceFile a) is selected from another record, if it exists b) uses the constant, if not.
    In SQL Command the commands (without placeholders) look:
    declare c integer;
    res varchar(30);
    key_var varchar(100);
    def_lang_var varchar(5);
    begin
    key_var := 'newString';
    def_lang_var := 'en';
    res := 'ap_string.htm';
    select count(*) into c FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
    if c > 0 then
    select daSourceFile into res FROM TRANSLATIONSTRINGS WHERE daKey = key_var AND daLanguage = def_lang_var;
    end if;
    INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile) VALUES (key_var, 'cs', 'translation', 'N', res);
    end;
    However, such a query does not work in the query resource (multiline commands cannot be used?).
    Neither can I think of one line query that would provide the same functionality (tried to test with COALESCE).

    Yes, I got the point. The query looks like:
    INSERT INTO TRANSLATIONSTRINGS (daKey, daLanguage, daTranslation, daStringFlag, daSourceFile)
    SELECT daKey, daLanguage, daTranslation, daStringFlag, daSourceFile FROM (
    select 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, daSourceFile FROM TRANSLATIONSTRINGS WHERE daKey = 'newString1' AND daLanguage = 'cs' UNION ALL SELECT 'newString1' daKey, 'en' daLanguage, 'transl' daTranslation, 'N' daStringFlag, 'default' daSourceFile FROM DUAL)
    WHERE rownum<=1;
    so that's the way how to solve it via SQL.
    (Since I can't use DECLARE, I need to bind entry parameters as many times as they appear in the query - not a very nice way, but it works).
    The question still is, whether there is a way how to use a multiline query in Component Queries. Even though it is not mentioned specifically in the documentation, it seems it is NOT to be possible by design. So the real question is really WHY - I guess it would be a little bit more convenient to begin/commit transactions, use variables, etc. in a multiline query.
    Yet, Sam, thanks!

  • Mixing SQL Command parameters and UI created parameters

    Post Author: shecter
    CA Forum: Data Connectivity and SQL
    I'm using Crystal Reports XI.  I've created a report with an SQL Command - no other tables or views. I want to allow my users to be able to choose data from a dynamic parameter and have the SQL read that and spit out the results. I was able to add a parameter to the SQL using the Parameter column in the Command window. This allows my user to type in a parameter. However, when I run the report after creating a parameter using the UI (i.e. Field Explorer/Parameters/right clicking and selecting "new" and then adding the parameter to a field using the selection wizard), i first get a screen that shows me the parameter that I created in the SQL Command window, then I get a screen that shows me the UI created parameters. How can I make it show only one screen with all the parameters?  -Marc 

    Post Author: jenxia
    CA Forum: General
    SQL Command is :
    SELECT UNIQUE ContactID,  incomingAddress,applicationid,
    MediaStatus, MediaDirection, EndDateTime, StartDateTime
    FROM MMCAContactMediaViewwhere EndDateTime>= {?1-reportstarttime}  and  EndDateTime <= {?2-reportendtime}
    Order by ContactID
    Select formula using dynamic prompts as
    {Command.contactid} = {?ContactID} and{Command.applicationid} = {?ApplicationID} and{Command.incomingaddress} = {?IncomingAddress}

  • Report using ref cursor or dynamic Sql

    Hi,
    I never create a report using a ref cursor or a dynamic sql. Could any one help me to solve the below issue.
    I have 2 tables.
    1. Student_Record
    2. Student_csv_help
    Student_Record the main table where the data is stored.
    Student_csv_help will contain the all the column names of the Student_record.
    CREATE TABLE Student_CSV_HELP
    ENTRY_ID NUMBER,
    RAW_NAME VARCHAR2(40 BYTE),
    DESC_NAME VARCHAR2(1000 BYTE),
    IN_OUTPUT_LIST VARCHAR2(1 BYTE)
    SET DEFINE OFF;
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (1, 'S_ID', 'Student ID', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (2, 'S_Name', 'Student Name', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (3, 'S_Join_date', 'Joining Date', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (4, 'S_Address', 'Address', 'Y');
    Insert into TOA_CSV_HELP
    (ENTRY_ID, RAW_NAME, DESC_NAME, IN_OUTPUT_LIST)
    Values
    (5, 'S_Fee', 'Tution Fee', 'N');
    commit;
    CREATE TABLE Student_record
    S_ID NUMBER,
    S_Name VARCHAR2(100 BYTE),
    S_Join_date date,
    S_Address VARCHAR2(360 BYTE),
    S_Fee Number
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (101, 'john', TO_DATE('12/17/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94777', 2000);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (102, 'arif', TO_DATE('12/18/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94444', 3000);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (103, 'raj', TO_DATE('12/19/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94555', 2500);
    Insert into Student_record
    (S_ID, S_Name, S_Join_date, S_Address,S_Fee)
    Values
    (104, 'singh', TO_DATE('12/20/2009 08:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'CA-94666', 2000);
    Commit;
    Now my requirement is:
    I have a form with Student_record data block. When i Click on print Button on this form. It will open another window which has Student_CSV_HELP.DESC_NAME and a check box before this.
    The window look like as below:
    check_box       DESC_NAME+
    X                   S_ID+
    --                   S_Name+
    X                   S_Join_date+
    X                   S_Address+
    --                  S_Fee+
    X  means check box checked.+
    --  means check box Unchecked.+
    After i selected these check boxes i will send 2 parameters to the report server
    1. a string parameter to the report server which has the value 'S_ID,S_Join_date,S_Address' (p_column_name := 'S_ID,S_Join_date,S_Address');
    2. the s_id value from the student_record block (p_S_id := '101');
    Now my requirement is when i click on run. I need a report like as below:
    Student ID : 101+
    Joining Date : 12/17/2009 08:00:00+
    Address : CA-94777+
    This is nothing but the ref cursor should run like as below:
    Select S_id from student_record block S_id = :p_S_id;
    Select S_Join_date from student_record block S_id = :p_S_id;
    Select S_Address from student_record block S_id = :p_S_id;
    So, according to my understanding i have to select the columns at the run time. I dont have much knowledge in creating reports using ref cursor or dynamic sql.
    So please help me to solve this issue.
    Thanks in advance.

    Plain sql should satisfy your need. Try ....
    Select S_id, S_Join_date, S_Address
    from student_record
    where S_id = :p_S_id

  • Erratic Report Region Behavior with Dynamic SQL Queries

    I'm running HTMLDB v 1.5.1.00.12 and I've noticed some odd behavior with report regions using dynamic SQL queries. Every so often, our testers will run a page containing a dynamic sql report region and get the following error, (despite the fact the query was working only moments ago and no other developer has touched it):
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    or sometimes
    failed to parse SQL query:ORA-01403: no data found
    The only solution I've found so far is to:
    1) Make a copy of the failed report region.
    2) Disable or delete the original failed report region.
    The new copy of the report region runs without issue.
    My search of the forums turned up the following two threads, but neither provided me with a clear explanation of the cause, and how to avoid it:
    ORA-06502:PL/SQL: numeric or value error: character string buffer too small
    Re: Import Export Error (ORA-06502)
    The columns being returned are below the 4000 character limit, and the rows being returned are far less than 32k in size.
    Could this have anything to do with the way HTMLDB is internally storing the PL/SQL used to generate the dynamic SQL Query? Is there any known issue related to this with that version of HTMLDB?
    This problem occurs without any discernable pattern or consistency, making it hard to determine where I should focus my efforts in tracking down the cause.

    Hi all,
    My report seems to be behaving correctly once i set it to "Use Generic Column Names (parse query at runtime only)" :)
    Cheers,
    Joel

Maybe you are looking for