Formulas in sql

I have a table in sql that needs to hold specific formulas. For example 2% + .15 and I will need to use this column to figure out prices. How would I be able to do that, and what datatype does it have to be?
Debra has a question

I need to be able to store in sql any form of formula in a column called discount later on I will do the cost * whatever the discount is.
And as I said, you should really try to avoid it. It can be horrendeously complicated. Instead, identify the possible components in your formulas and make these column in a table or something like that. Then use a static expression from these columns.
If you really need to do formulas, T-SQL is completely the wrong venue. You need to be able to parse the formulas and have a language defined for them. So it will have to be .NET - which you can do inside SQL Server if needed. But as I said, try to avoid
it - it could take many hours to implement a solution.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Passing Params & Formulas to SQL Command & Strd Proc in CR 11.5 & 2008 - 1

    I am working with CR 11.5 and heavily use SQL Command rewrites and Stored Procedures (SPs)with the usual limitation that only single parameter values can be passed into SPs, and Parameters must be created within the SQL Command editor (and cannot be referenced to those generated in Field Explorer, or can they?)
    I understand from BE/CR's sales material for CR 2008 that multiple values can now be used under these conditions.  As I recall, Multivalue Parameters are actually arrays that can be made into comma delimited strings.
    Local StringVar StringExpression;
    Local NumberVar ArrayCount := Count({?Code});
    Local NumberVar i;
    if ArrayCount = 0
       then StringExpression := ""
    else
       StringExpression := {?Code}[1];
       i := 2; 
    While i <= ArrayCount Do
        StringExpression := StringExpression + ", " + {?Code}<i>;
        i := i + 1;
    See part 2 for continuation....

    Here is my use case (since most of my reports are against very large databases, running "tuned" SQL Commands is essential).
    SELECT
      PERSON.PatientName,
      PROBLEM.Code,
      PROBLEM.Description
      LASTLABS.HDID,
      RPTOBS.ObsDate,
      RPTOBS.ObsValue
    FROM
      ((PERSON INNER JOIN
        PROBLEM ON
            PERSON.PId = PROBLEM.PId) LEFT OUTER JOIN
         LASTLABS ON
         (PERSON.PId = LASTLABS.PId AND
          LASTLABS.HDID IN (28, 53, 67, 102) LEFT OUTER JOIN      -- Paramaterize
        RPTOBS ON
         (LASTLABS.HDID = C.HDID AND
          LASTLABS.MaxObsDate = RPTOBS.ObsDate AND
          LASTLABS.PId = RPTOBS.PId AND
          RPTOBS.Change IN (2, 5, 7))                             -- Paramaterize
    WHERE
        (PROBLEM.Code LIKE '249%' OR                              -- Paramaterize
         PROBLEM.Code LIKE '250%' OR                              -- Paramaterize
         PROBLEM.Code IN ('V77.1', 'V80')                         -- Paramaterize
    What I am looking for is a Parameterized form as follows....
    SELECT
      PERSON.PatientName,
      PROBLEM.Code,
      PROBLEM.Description
      PROBLEM.Qualifier,
      LASTLABS.HDID,
      RPTOBS.ObsDate,
      RPTOBS.ObsValue
    FROM
      ((PERSON INNER JOIN
        PROBLEM ON
            PERSON.PId = PROBLEM.PId) LEFT OUTER JOIN
        LASTLABS ON
         (PERSON.PId = LASTLABS.PId AND
          LASTLABS.HDID ({?HDID_In_Param}) LEFT OUTER JOIN          -- Paramaterize
        RPTOBS ON
         (LASTLABS.HDID = RPTOBS.HDID AND
          LASTLABS.MaxObsDate = RPTOBS.ObsDate AND
          LASTLABS.PID = RPTOBS.PID AND
          RPTOBS.Change ({?Change_In_Param}))                       -- Paramaterize
    WHERE
        (PROBLEM.Code {?Code_Like_Param} OR                         -- Paramaterize
         PROBLEM.Code {?Code_In_Param})                             -- Paramaterize
    Is this possible? Has it been thought of yet. Has passing in well-constructed @formulas been considered?

  • Need Help with Formula using SQL maybe

    I need help!  I work with Crystal reports XI and usually manage just fine with the Formula editor but his one I think will require some SQL and I am not good at that.
    We are running SQL 2000 I think (Enterprise Manager 8.0)  Our sales people schedule activities and enter notes for customer accounts.  Each is stored in a separate table.  I need to find activities that are scheduled 240 days into the future and show the most recent note that goes with the account for which that activity is scheduled.
    The two tables, Activities and History, share the an accountID field in common that links them to the correct customer account.   I want to look at dates in the Startdate.Activities field more than 240 days in the future and show the most recent note from the History table where the accountid's match. I figure my query will contain a join on AccountID.Activities and AccountID.History used with Max(completedate.History) but I do not understand how to word it.
    I would like to perform all this in crystal if possible.  I humbly request your help.
    Membery

    You SQL would look something like this...
    SELECT
    a.AccountID,
    a.BlahBlahBlah, -- Any other fields you want from the Activities table
    h.LastComment
    FROM Activities AS a
    LEFT OUTER JOIN History AS h ON a.AccountID = h.AccountID
    WHERE (a.ActivityDate BETWEEN GetDate() AND DateAdd(dd, 240, GetDate()))
    AND h.HistoryID IN (
         SELECT MAX(HistoryID)
         FROM History
         GROUP BY AccountID)
    This method assumes that the History table has a HistoryID that increments up automatically each time a new comment is added... So a comment made today would always have a higher HistoryID that one made yesterday.
    If I'm wrong and there is no HistoryID or the HistoryID doesn't increment in a chronological fashion, it can still be done but the code is a bit more complex.
    HTH,
    Jason

  • Help required urgently in formulating a sql query

    I need to formulate a query the detials of which are as follows
    I have a table with columns
    cid,st_dt,end_dt,yob,status
    the data could be like
    1,25-dec-99,31-dec-99,1964,null
    1,01-jan-00,null,1963,null
    1,27-dec-99,31-jan-00,null,a
    1,04-feb-00,null,null,b
    In a row in this table either yob or status
    is null there can't be values for both in a single row.
    Now i need an output for the above like
    1,25-dec-99,27-dec-99,1964,null
    1,28-dec-99,31-dec-99,1964,a
    1,01-jan-00,31-jan-00,1963,a
    1,01-feb-00,03-feb-00,1963,null
    1,04-feb-00,null,1963,b
    here as in the base table the end dt for
    any row is null then it would have all the
    attributes from that start dt onwards.
    Can anybody help me out please. I need one sql script to get this output.
    Thanks in advance.
    null

    Hey,
    Here I have assumed that the table3 has a column named effdt and if it is then,
    Select t1.deptid,t2.report2dept,t2.parent_org
    from table1 t1, table2 t2 , table3 t3
    where t1.deptid = t2.deptid
    and t2.deptid = t3.deptid
    and t3.effdt = (select max(effdt) from table3 where employeeid = t3.employeeid group by employeeid);
    This may help you.
    Regards,
    Nilesh Goswami.

  • Percentile excel formula in SQL

    Hi Friends,
     I want to do percentile function of excel in sql but I'm unable to do it. Below link shows the working of percentile function in excel
    http://office.microsoft.com/en-us/excel-help/percentile-HP005209211.aspx
    I want to achieve the same in sql. Any help is highly appreciated. Also attaching table script for ease.
    Create Table #temp(
    A int
    insert into #temp values (1)
    insert into #temp values (3)
    insert into #temp values (2)
    insert into #temp values (4)
    Thanks.

    what is the sql server version?
    if you are using SQL 2012 try below links,
    http://technet.microsoft.com/en-us/library/hh231327.aspx
    http://technet.microsoft.com/en-us/library/hh231473.aspx
    Please use Marked as Answer if my post solved your problem and use
    Vote As Helpful if a post was useful.

  • SQL or Formula in Crystal 8.5?

    Hello Forum Oracles!
    I am new to Crystal and SQL. I have had no formal training in any aspect of IT but have a good understanding of certain things. I have been around windows based PC since the early 1990s. I need help in writing a formula or SQL I know not which. This is my problem.
    We are a vending company and have men that fill up these machines with stock. I am producing a report to forcast their stock requirments based on the amount of machines they service, new machines in their area and historical usage of stock. I have a parameter where I can enter usage in a period between dates but what i would like is for the report to automaticlly tell me what they have used in the last 42 days. I have used the SQL experssion {fn NOW()}-42 to return a date 42 day pervious but I am now stuck on how to get this in a report. This is as far as my logic and abilities take me:
    vw_StockMovement_Usage."amendedAt" BETWEEN {fn NOW()} AND {fn NOW()}-42
    Your help will be very much apprecated.
    David

    Hi David,
    You can get rid of the parameter and instead use a record selection formula like this (Report > Selection Formulas > Record):
    vw_StockMovement_Usage."amendedAt" >= dateadd("d",-42,currentdate)
    Hope this helps!
    -Abhilash

  • "SQL Expression Fields" branch missing from Formula Workshop/Field Explorer

    Hello,
    I am using Crystal Reports XI R2 SP3.  Some recent information I have seen suggests that I should use a feature called "SQL Expression Fields".  If I search the built-in Crystal Report help for "SQL Expressions", on the help pages I see that there is a "SQL Expression Fields" branch in the left pane of the Formula Workshop, just under Formula Fields and just above Selection Formulas (it's unfortunate that I cannot embed a bitmapped screen print of this).  The left pane of the Formula Workshop looks like this:
    Report Custom Functions
    Repository Custom Functions
    Formula Fields
    SQL Expression Fields
    Selection Formulas
    Formatting Formulas
    However, in my local copy of Crystal Reports the SQL Expression Fields branch does not exist - the left pane of the Formula Workshop looks like this:
    Report Custom Functions
    Repository Custom Functions
    Formula Fields
    Selection Formulas
    Formatting Formulas
    Is there some special patch, add-in or plug-in that's necessary to enable this functionality?
    Thanks in Advance,
    Bob Gardner

    I set up a DSN to a local MS Access database and used it for an ODBC connection.  Once connected, the SQL Expression Fields branch was available in Field Explorer and Formula Workshop.
    But I am developing reports for an ERP system that uses Oracle 10g databases - I have no choice but to use Oracle 10g databases as data sources for my reports.  I am not sure how to set up an ODBC connection to an Oracle database as I have never had to do so - will SQL Expression Fields not work with the native Oracle driver?
    Thank you,
    Bob Gardner

  • SQL Aggregate function and Subquery issues

    Hello,
    I'm trying to create an SQL statement that gives the rate of all Urgent surgeries Grouped by sector (i.e Surgery, Radiology), and Fiscal year
    To do this I need to divide the sum of surgeries with a state "Urgent" by the total surgeries
    In order to pull all the Total surgeries I would need to exclude the surgeries with the state "Cancelled", AND make sure to get rid of duplicates a single surgery may have.
    So this is what I came up with, but I'm not able to apply the following formula in SQL for the rate of Urgent surgeries:
    TOTAL OF URGENT SURGERIES / TOTAL SURGERIES
    Note that the Select statement within the WITH CLAUSE runs successfully when running it separately
    With T1 As(
    SELECT                          
    b."etat",                         
    c."secteur",                    
    d.annee_fiscale_full,                         
    d.periode,
    SUM(Count(distinct b."Cle_requete")) OVER (PARTITION BY b."etat", c."secteur", d.annee_fiscale_full, d.periode) AS TOTAL_SURGERIES
    FROM vsRequete a,                         
    vsEtats b,                         
    vsOperation c,                         
    periode_financiere d,                         
    vstemps_operatoires e                         
    WHERE b."etat" <> 'Cancelled'
    AND (b."Cle_requete" = a."Cle_vsRequete")                         
    AND (c."Cle_requete" = a."Cle_vsRequete")                         
    AND (b."Cle_requete" = c."Cle_requete")                         
    AND (a."Cle_vsRequete" = e."Cle_requete")                         
    AND c."date_operation" = d.per_fina_date                         
    GROUP BY                          
    b."etat",                         
    c."secteur",
    --a."type_visite",
    d.annee_fiscale_full,                         
    d.periode )
    SELECT
    ---- ***NOTE***: SHOULD I BE USING THE FOLLOWING ANALYTIC FUNCTION FOR THE RATE OF URGENT SURGERIES
    ---- RATIO_TO_REPORT(T1.TOTAL_SURGERIES) OVER () As URGENT_SURGERY_RATE,
    T1."secteur",                    
    --a."type_visite",
    T1.annee_fiscale_full,                         
    T1.periode
    FROM T1
    Where T1."etat" = 'Urgent'
    ORDER BY
    T1.annee_fiscale_full,                         
    T1.periode,                    
    T1."secteur";
    Thanks for your help
    Edited by: Ruben_920841 on Dec 21, 2012 1:40 PM
    Edited by: Ruben_920841 on Dec 21, 2012 1:41 PM

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Ruben_920841 wrote:
    Hello,
    I'm trying to create an SQL statement that gives the rate of all Urgent surgeries Grouped by sector (i.e Surgery, Radiology), and Fiscal year
    To do this I need to divide the sum of surgeries with a state "Urgent" by the total surgeries
    In order to pull all the Total surgeries I would need to exclude the surgeries with the state "Cancelled", AND make sure to get rid of duplicates a single surgery may have.
    So this is what I came up with, but I'm not able to apply the following formula in SQL for the rate of Urgent surgeries:
    TOTAL OF URGENT SURGERIES / TOTAL SURGERIES
    Note that the Select statement within the WITH CLAUSE runs successfully when running it separately
    With T1 As(
    SELECT                          
    b."etat",                         
    c."secteur",                    
    d.annee_fiscale_full,                         
    d.periode,
    SUM(Count(distinct b."Cle_requete")) OVER (PARTITION BY b."etat", c."secteur", d.annee_fiscale_full, d.periode) AS TOTAL_SURGERIES Is it possible, in a group of rows with the same "Cle_requete", for some rows to have "etate"='Urgent' and other rows to have some other value besides 'Cancelled'? If so, how is that counted? Include an example or two in your sample data and results.
    FROM vsRequete a,                         
    vsEtats b,                         
    vsOperation c,                         
    periode_financiere d,                         
    vstemps_operatoires e                         
    WHERE b."etat" <> 'Cancelled'This site doesn't like to display the &lt;&gt; inequality operator. Always use the other (equivalent) inequality operator, !=, when posting here.
    AND (b."Cle_requete" = a."Cle_vsRequete")                         
    AND (c."Cle_requete" = a."Cle_vsRequete")                         
    AND (b."Cle_requete" = c."Cle_requete")                         
    AND (a."Cle_vsRequete" = e."Cle_requete")                         
    AND c."date_operation" = d.per_fina_date                         
    GROUP BY                          
    b."etat",                         
    c."secteur",
    --a."type_visite",
    d.annee_fiscale_full,                         
    d.periode )
    Select
    ----- ***NOTE***: SHOULD I BE USING THE FOLLOWING ANALYTIC FUNCTION FOR THE RATE OF URGENT SURGERIES
    ------ RATIO_TO_REPORT(T1.TOTAL_SURGERIES) OVER () As URGENT_SURGERY_RATE,That depends on your data, and your desired results. Based on what you've said so far, I think not. It's more likely that you'll want to use a CASE expression to get a count of the 'Urgent' surgeries.
    T1."secteur",                    
    --a."type_visite",
    T1.annee_fiscale_full,                         
    T1.periode
    FROM T1
    Where T1."etat" = 'Urgent'
    ORDER BY
    T1.annee_fiscale_full,                         
    T1.periode,                    
    T1."secteur";The forum FAQ {message:id=9360002} explains how to use \ tags to preserve spacing when you post formatted text, such as your query.
    It sounds like your problem is similar to this one:
    "What percentage of the employees (not counting SALESMEN)  in each department of the scott.emp table are CLERKS?"
    Here's one way you might answer that:WITH     got_cnts     AS
         SELECT     deptno
         ,     COUNT ( DISTINCT CASE
                             WHEN job = 'CLERK'
                             THEN ename
                        END
                   )               AS clerk_cnt
         ,     COUNT (DISTINCT ename)     AS total_cnt
         FROM     scott.emp
         WHERE     job     != 'SALESMAN'
         GROUP BY deptno
    SELECT     deptno
    ,     clerk_cnt
    ,     total_cnt
    ,     100 * clerk_cnt
         / total_cnt     AS clerk_pct
    FROM     got_cnts
    ORDER BY deptno
    Output:DEPTNO CLERK_CNT TOTAL_CNT CLERK_PCT
    10 1 3 33.33
    20 2 5 40.00
    30 1 2 50.00

  • SQL statement help

    If someone would be so kind, I need help in formulating a SQL statement.
    Table A - employees(empoyee_id, employee_name, status)
    This table contains all employees
    employee status can be one of three values (A=active, T=temporary, I=inactive)
    Table B - savings_program(employee_id, plan_type)
    This table only has employee_id's of those that participate in a savings program (subset of all employees).
    plan_type can be one of three numeric values (30,35,40)
    I need SQL to report a.employee_id,a.employee_name,b.plan_type (return plan_type 30,35, or none)of all active employees in Table A that don't participate in Table B plan_type 40.
    Working with version 9iR2. Thanks!
    Edited by: fosterk on Nov 21, 2008 12:59 PM

    The tables and columns above were for demo purposes but actual code I'm trying is below. Please excuse me I'm more of an SA type so SQL is not my thing.
    As you can see from the first SQL statement below I know that I have exactly
    3,000 employees that meet this criteria. The second SQL statement is my attempt to return the rows I want (I'm just nesting it in a count(*) until the numbers look right)
    The last statement is what was given to me by someone else (seeking my help haha) trying to resolve it and it only returns 3 rows. This SQL shows the actual columns that we're trying to return from both tables.
    HR> select count(*) from ps_All_employees where empl_status != 'T'
    2 and emplid not in
    3 (select emplid from ps_savings_pt_vw where plan_type = 40)
    4 /
    COUNT(*)
    3000
    HR> select count(*) from (
    2 (select * from ps_all_employees where empl_status != 'T') a left outer join
    3 (select emplid from ps_savings_pt_vw where plan_type != 40) s
    4 on a.emplid = s.emplid
    5 )
    6 /
    COUNT(*)
    4587
    select count(*) from (
    select a.location, a.ssn, a.first_name, a.last_name, a.birthdate, a.orig_hire_dt, a.hire_dt, a.location, a.street1,
    a.street2, a.city, a.state, a.zip, s.plan_type
    from ps_all_employees a, ps_savings_pt_vw s
    where a.empl_status != 'T' and
    a.emplid = s.emplid and
    a.emplid not in (select s.emplid from ps_savings_pt_vw s where s.plan_type = 40)
    COUNT(*)
    3

  • Advanced style rule (attribute) column can be a sql expr

    Just wondering if folks have used complex formulas or sql expressions for the rule column for an advanced style. If yes please post examples in response.
    The rule column used in an advanced style can be a sql expression. e.g. (TOTPOP/LANDSQMI) POPDENSITY to display a thematic map of population density instead of total population. The theme def would look like
    <?xml version="1.0" standalone="yes"?>
    <styling_rules>
    <rule column="(TOTPOP/LANDSQMI) POPDENSITY">
    <features style="V.POPPSQMI"> (landsqmi is not null AND
    landsqmi &gt; 0) </features>
    </rule>
    </styling_rules>
    In particular has anyone used CASE, DECODE, NTILE etc.?

    Try changing the following properties:
    autosubmit = true;
    immediate = true;
    Here is a link where the user uses a transient attribute for the rows in his table:
    Technology on my way...:): ADF 11g : CheckBox Demo (Select one checkbox in table, Select all/Deselect all)
    Hope that helps.
    Regards,
    Frederico.

  • Error in Report Execution and Viewing

    We have some reports that were originally developed in Crystal Reports 5 running on Crystal Reports Xi now.
    Our users reported getting the following error while printing
    Error in File C:\temp\{72703900-5223-49CB-8C2A-A83FCFCA4447}.rpt: The request could not be submitted for background processing.
    When I refresh this report using the crsytal reports tool (desktop tool), I see the report, but as I am browsing the report using the navigation buttons, I get the following error on one page. After reporting this error, the application shuts down.
    CiceroUIWndFrame:crw32.exe - Application Error
    The exception Integer division by zero.
    (0xc000094) occurred in the application at the location  x2c03a340
    Click OK to terminate program
    Click CANCEL to debug program
    I checked the formulas and sql queries on this report and there is no division of any sort being performed. There is some grouping being done.. but the flelds being grouped on have data and I think its unlikely that the grouping would cause this error.
    I am using windows XP sp2. The server is a windows 2000 server with IIS going against a sql server 9 version database.
    Thanks,
    Jayashree

    Hi James,
    Thank you for your quick response.
    I checked the report and the remainder functions is not being used.
    The only formulas being used in the report are the following.
    UpperCase ([1])
    + ", " + - This is set to @name
    {@name} + " (" + + ")"
    There are some formatting formulas set on the above values, but other than that, there is a sql query and the "select distinct rows" and "perform grouping on server" is selected.
    Thanks,
    Jayashree

  • JRC for Crystal Reports for Eclipse V2.0 Parameter Problems

    Scenario:
    I have a report that displays the Function Group Name for a certain individual and all the Functions included in that Function Group. The following are the tables involved:
    USER, FUNC_GROUP (contains description of the group) and FUNC_GROUP_LIST (the actual functions in the FUNC_GROUP).
    The SQL command for the main report is: select id, name, description from FUNC_GROUP, USER where FUNC_GROUP.id = USER.default_func_group_id
    The sub-report which lists the functions for the Function Group has the following SQL command: select id, name from FUNC where func_group_id = <main report's FUNC_GROUP.id>
    The problem is my current code still flags missingParameterValueError error whenever I changed the DB location and set the parameters.
    Code used for setting of db connection:
    private void setDBConnection(ReportClientDocument doc) throws ReportSDKException {
        IConnectionInfo newConnectionInfo = new ConnectionInfo();
        newConnectionInfo.setAttributes(new PropertyBag(connectionProperty));
        newConnectionInfo.setUserName(getLoginname());
        newConnectionInfo.setPassword(getPassword());
        //preserve subreport links
        SubreportController src = doc.getSubreportController();
        Map<String, SubreportLinks> linkMapper = new HashMap<String,SubreportLinks>();
        for(String subreportName : src.getSubreportNames()){
            linkMapper.put(subreportName,
                (SubreportLinks) src.getSubreportLinks(subreportName).clone(true));
        //If this connection needed parameters, we would use this field. 
        Fields<IParameterField> pFields = doc.getDataDefController().getDataDefinition().getParameterFields();
        replaceConnectionInfos(doc.getDatabaseController(), newConnectionInfo, pFields);
        IStrings strs = src.getSubreportNames();
        Iterator<String> it = strs.iterator();
        while (it.hasNext()) {
          String name = it.next();
          ISubreportClientDocument subreport = src.getSubreport(name);
          pFields = subreport.getDataDefController().getDataDefinition().getParameterFields();
          replaceConnectionInfos(subreport.getDatabaseController(), newConnectionInfo, pFields);
        //reconnect subreport links since when using replaceConnection links are erased
        for(String subreportName : src.getSubreportNames())
          src.setSubreportLinks(subreportName, linkMapper.get(subreportName));
    Edited by: Rizza Lynn Ponce on Jun 2, 2009 11:56 AM

    >
    Ted Ueda wrote:
    > Do you look at the report links you're saving before the connection changes, to see if it's being saved, and added back?  It'll be interesting what type of link it is.
    I've run the program in debug mode and inspected the following:
    src.getSubreportLinks(subreportName).getSubreportLink(0).getSubreportFieldName()
    src.getSubreportLinks(subreportName).getSubreportLink(0).getMainReportFieldName()
    src.getSubreportLinks(subreportName).getSubreportLink(0).getLinkedParameterName()
    before the change in connection and after the change in connection in both main and subreport and after adding back the links. The values monitored did not change.
    Am I looking at the correct things? Or is there another value I need to monitor?
    >
    > Is it possibly to a stored proc parameter that is no longer there in the subreport after the database change?
    I am not using any stored procs, I just formulated an SQL for retrieval in both main and subreport.
    >
    > If so, you'd need to redefine the link before applying.
    >
    > Sincerely,
    >
    > Ted Ueda
    What do you mean redefine?
    Additional info:
    The current template I'm using accepts the value from main report (FUNC_GROUP.id) which is in turn used as a parameter in the SQL command in the subreport. This throws an error when exporting via JRC.
    However, I tried some modifications in the SQL command in the subreport. I've included the Function Group ID in the select clause (select id, name, func_group_id from FUNC) instead of using it in the where clause. Then in the linking of the main and the subreport, I chose filter data in subreport by func_group_id matching FUNC_GROUP.id in main report. Exporting in JRC this report worked well and deliver the same data as the original template. The problem is I think it takes longer because all data in FUNC table is retrieved. And also as a framework developer, I prefer not limiting the developers regarding the style on how they connect main and subreport in CRW (I'd personally say I'm more fond of using the original template as I think the modified template retrieves unneeded data).

  • Keep DB Connection Open

    I have an Oracle stored procedure that I need to call for a list of records in Crystal.
    What I have done is created a UFL to make the call and provide the return results.
    I call the Custom Function for each record returned however, it's taking a long time to process.
    I believe this is because the connection to the oracle database is being opened, called and closed for each record.
    Is there any way to open the connection when the reports starts running, return the results for each record and then close the connection when the report completes?
    Any help would be appreciated.
    FYI - I am using CRXI R2
    Ray

    Hi Raymond,
    The reason why CR opens/closes for each record is because you are using a UFL it's going to be processed on the second pass of the report which means because it's a formula CR will process it after the connection is closed. If CR can convert the formula into SQL then it happens server side but in your case you need to run the query for each record.
    Have you had a look at using a Command Object? It would require returning all of the data but at least the ufl function would then filter on the Command data and not hit the database. You may have to re-write your UFL functions so it doesn't go to the DB but uses the cached data in the Command object.
    Another option would be to write your own OLE DB Provider. DataDirect who we partner with for data sources, offers an SDK so you can build in security and anything else you need or would like to have.
    http://web.datadirect.com/products/custom-driver-sdk/index.html
    As for stopping CR from disconnecting that won't happen. We release the connection to free resources once we are done, keeping the connection open causes problems for all applications like Brian indicated.
    You may have to re-design your report and do the filtering client side rather than server side.
    Thank you
    Don

  • Date Calculating...

    Guyz,
    I have two block on a single canvas.
    (Ex: Block1 and Block2)
    Block1 is Tubular (With Effective_date) Date Field - Database Block
    Block2 is Form Type (Normal) CAL_DIS Number datatype , Non database block as well.
    i am fetching the dates from database with the below cursor in Block1 on WNFI Trigger
    DECLARE CURSOR C1 IS SELECT EFF_DATE  FROM MN_EMP_DEP_DET WHERE EMPID=:PARAMETER.EMPID AND CO_TKT=1 AND EFF_DATE IS NOT NULL;
    BEGIN
         GO_BLOCK('BLOCK1');
         OPEN C1;
         LOOP
              FETCH C1 INTO :BLOCK1.EFFECTIVE_DATE;
              EXIT WHEN C1%NOTFOUND;
              NEXT_RECORD;
         END LOOP;
         CLOSE C1;
         FIRST_RECORD;
    END;So im getting records properly as below....and on Block2 item i gave the below formula in CAL_DIS item
    01/01/2005
    01/06/2007
    01/08/2010
    01/08/2012
    FLOOR(MONTHS_BETWEEN(SYSDATE,:BLOCK1.EFFECTIVE_DATE))/12when ever i'm putting the cursor on the above date field its giving different results in block2 cal_dis item, is there any other way that i can calculate all the above dates at once with the above formula into CAL_DIS item?
    im using forms 6i Database 9i
    Edited by: Moazam Shareef on Jan 2, 2013 5:12 AM
    Edited by: Moazam Shareef on Jan 2, 2013 5:13 AM
    Edited by: Moazam Shareef on Jan 2, 2013 5:13 AM

    Thanks for your help Steve.
    but here i need the total calculated result where the dates are different in tubular block i create two block here one database tubular block and another control block where i place two non database items DIS_ID and DIS_CAL i place the below formula in DIS_CAL and on :CTRL.DIS_ID i wrote the below code in on KEY-NEXT-ITEM
    GO_BLOCK('MN_EMP_DEP_DET');
    SET_BLOCK_PROPERTY('MN_EMP_DEP_DET', DEFAULT_WHERE, 'EMPID=:CTRL.DIS_ID AND CO_TKT=1');
    EXECUTE_QUERY;
    GO_ITEM('CTRL.DIS_ID');Formula
    FLOOR(MONTHS_BETWEEN(SYSDATE,:MN_EMP_DEP_DET.EFF_DATE))/12The query executed properly, but i need the total result from the tubular block, where it shows only single column result when i place the cursor in first record its shows *3.00* and in another record its shows *2.00* in the DIS_CAL, the result should display *5.00* in DIS_CAL using the above floor formula, you can see the below snaps.
    http://s1.postimage.org/y87qof4rv/res_1.jpg
    http://s1.postimage.org/rvslel1pn/res_2.jpg
    I tried the below query run sucessfully but cannot use in formula column
    SQL> SELECT FLOOR(MONTHS_BETWEEN(SYSDATE,EFF_DATE)/12) FROM MN_EMP_DEP_DET
      2  WHERE EMPID=1657 AND CO_TKT=1
      3  ;
    FLOOR(MONTHS_BETWEEN(SYSDATE,EFF_DATE)/12)                                                         
                                             3                                                         
                                             2                                                         
    SQL> SELECT COUNT(FLOOR(MONTHS_BETWEEN(SYSDATE,EFF_DATE)/12)) FROM MN_EMP_DEP_DET
      2  WHERE EMPID=1657 AND CO_TKT=1;
    COUNT(FLOOR(MONTHS_BETWEEN(SYSDATE,EFF_DATE)/12))                                                  
                                                    2                                                  
    SQL> SELECT SUM(FLOOR(MONTHS_BETWEEN(SYSDATE,EFF_DATE)/12)) FROM MN_EMP_DEP_DET
      2  WHERE EMPID=1657 AND CO_TKT=1;
    SUM(FLOOR(MONTHS_BETWEEN(SYSDATE,EFF_DATE)/12))                                                    
                                                  5                                                     I want the last SUM query into my DIS_CAL
    Regards
    Edited by: Moazam Shareef on Jan 4, 2013 11:25 PM

  • Changing datasource at runtime

    In reporting tools like BIRT, it is possible to change the database URL, user name etc at runtime. When I scheduled a report using infoview I could not see any means to change the JDBC URL to point to another database host.

    Hi Pradeep,
    Please find the steps below to create a Business View with the Dynamic data connection. And yes it is possible to add connection to "dynamic data connection" list.
    To create a Data Connection
    u2022     On the File menu, select New, and then select Data Connection The u201CChoose a Data Sourceu201D dialog box appears
    u2022     Expand the folders as necessary and select a data source
    u2022     Click OK and save a Data Connection object
    As we are creating the DDC we need to have minimum two Data connections.
    To create a Dynamic Data Connection
    u2022     On the File menu, select New, and then select Dynamic Data Connection. The u201CChoose a Data Connectionu201D dialog box appears
    u2022     Expand the folders as necessary and select a Data Connection.
    u2022     Click Add.
    u2022     Continue selecting and adding Data Connections as necessary; click Close when you are finished and save a Dynamic Data Connection
    To create a Data Foundation
    u2022     On the File menu, select New, and then click Data Foundation.The u201CChoose a Data Connectionu201D dialog box appears.
    u2022     Select a Data Connection or a Dynamic Data Connection and click OK. If you want to add another Data Connection or Dynamic Data Connection, click Add Connection. Expand the various table nodes, select a table, and click Add.
    u2022     Continue adding tables as needed.
    u2022     Click Close.
    To create a Business Element
    u2022     On the File menu, select New, and then select Business Element. Expand and select the Business Fields in tables, formulas, and SQL expressions; then, click Add.
    u2022     Click Close.
    To create a new Business View
    u2022     On the File menu, select New, and then select Business View.
    u2022     In the Object Explorer, right-click the Business Elements node, and click Insert Business Elements.
    u2022     Click Add. Continue selecting and adding Business Elements as required.
    u2022     Click Close to continue
    Then you can have your Crystal Reports based on these Business Views.
    I hope this helps you and let me know if this works for you.
    Prashant.

Maybe you are looking for

  • Which license type do we need to buy, standard or professional?

    We have been helping a customer to develop a web based system built around Flash media server. For our work we have used the developer edition. Things are going well and now our customer is now looking to go live and so wants to purchase a full media

  • Can you open a calculator and add or subtract within a cell?

    I am trying to see if there is a way to use the number pad as a calculator and add figures then enter into a cell for further use.  I want to eliminate the use of my adding machine if possible and just use my keyboard to do my additions and enter dir

  • How to start up MAC mini only in the verbose mode (command line) , no GUI

    Can anyone let me know how I can set up the mac mini to ALWAYS boot into a verbose mode only, no GUI interfaces at all? Mac Mini   Mac OS X (10.4.6)   Mac Mini   Mac OS X (10.4.6)  

  • Require functional module - catalogs and codes

    Hi all, I am looking for a functional module for Catalogs And Codes. as i want to change the non sap data to sap form. for that i need to do custom code as LSMW is not working for me. So please help me out in having functional module or BAPI for the

  • Private synonym working

    Hi, I have created a private synonym and granted a select privilege in one schema (webcen) as shown below, it is working fine,but the same thing is not working in another schema. CREATE SYNONYM HZ_LOCATIONS FOR OPERAPPS.HZ_LOCATIONS; connected to ope