Sql problem - sum is Incorrect

can anyone show me the light here.
this statment produce the wrong sum (chgTotal) SUM(unit * charge)
- it duplicates the sum for some reason. why?
SELECT TI.ID, TI.firstName, TI.middleName, TI.LastName,  DEP.depositeDate AS InsDatePay, DEP.depositAmount AS insAmnt,
CRG.dueDate,  MIN(FL.DepartureDate) AS leaving , MAX(FL.DepartureDate) AS returning, SUM(unit * charge) AS chgTotal
FROM infoAS TI, deposit AS DEP, segments FL, payment AS CRG
WHERE TI.ID = DEP.ID
AND FL.ID = DEP.ID
AND CRG.ID = DEP.ID
AND DEP.Comment='insurance' AND TI.Status <>'cancelled'
GROUP BY FL.IDthanks

You probably have more than two rows with the same ID in one of the DEP, TI or CRG tables...

Similar Messages

  • SQL LDR LKM generating incorrect CTL file

    Hi,
    The LKM for SQL LDR is generating incorrect CTL file for a fixed length data file. Due to this the ODI is erring out.
    Here are the contents of the CTL file:
    SnpsOutFile "-File=//Myserver/myfile.ctl"
    OPTIONS (
         SKIP=0,
         ERRORS=0,
         DIRECT=TRUE
    LOAD DATA
    INFILE "//Myserver/myfile.RDY"
    BADFILE "//Myserver/myfile.bad"
    DISCARDFILE "//Myserver/myfile.dsc"
    DISCARDMAX 1
    INTO TABLE ORA_SCHEMA.C$_0RAW_TABLE
         C1_CHAR9     POSITION(:),
         C2_CHAR2     POSITION(:),
         C3_CHAR6     POSITION(:),
         C4_CODE          POSITION(:),
         C5_RAWG_CODE     POSITION(:),
         C6_E_NUMBER     POSITION(:),
         C7_T_NUMBER     POSITION(:),
         C8_C_COLOR     POSITION(:),
         C9_D_COLOR     POSITION(:),
         C10_R_CODE     POSITION(:)
    Why is "POSITION(:)" not getting the numbers before and after ":" ?
    I reverse engineered this file and have the correct values for "Physical Length" and "Logical Length"
    TIA,
    Ankit

    Hi Ankit,
    I think the column transformation mappings are set on the Source (radio button) in the Integration Interface Mapping window.
    Change the column transformation mappings to be executed on STAGE .
    It should resolve this issue.
    Thanks,
    Sutirtha

  • Two SQL problems

    First problem...
    SQL root will not access all databases...
    If I try to access al databases using SQL Administrator the connection is refused even if I use root.
    all databases are accessable va individual username and password..
    Tried changing root password with GUI but makes no difference...
    Second SQL problem...
    10.4.11 server failed all raid volumes so corrupted no rescue was possible on any volume reinstall failed as well...
    Have rebuilt the server using 10.5.6 I will have to manually import the SQL databases from the old server... what do I do ??? I cannot boot the old server so cannot do an SQL export or anything...
    Thanks...

    Hi Jun,
    Can i contribute a little for ur 2nd problem.
    This error is coz, If u are using a filter against a File "data store" u can't test it, only against RDBMS query will be tested at data store level.
    Well, for using that filter and make sure its working, drag and drop the source file in the interface (u can get the filter) and make it to execute on STAGING.
    Thanks,
    Guru

  • Small SQL problem

    Hello,
    I have a small SQL problem...
    I am designing an online bank using servlets for a university project and it allows customers to view their statements. They select which of their account numbers they want to view the statement for and the start and end date of the statement.
    The problem lies with the dates. Here is the SQL:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And date>=1/1/01 And date<=31/1/01;
    All of the books I have looked at show dates in '1/1/01' format but whenever I try it this way I get a 'Data type mismatch in criteria expression' error (the 'date' field in the Database IS a Date type).
    Although, whenever I run the query in Access and prompt the user to enter the start and end date, it works fine.
    I have spoken to a few people and no-one seems to know why it is not working.
    Any ideas???
    Thanks

    If your database is MS Access and you don't expect to switch to something else, then write this:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And [date]>=#1/1/01# And [date]<=#1/31/01#
    Note that you MUST format your dates as MM/DD/YY and not as DD/MM/YY, that's an Access rule, and that you will probably have to "quote" your column name "date", which I think is a reserved word in SQL and hence a bad choice for column name.
    Personally I always use PreparedStatements. That way my SQL would look like this:
    SELECT date, details, amount, balance
    FROM HISTORY
    WHERE bankaccnumber=13494925 And date>=? And date<=?
    and I would use the setDate() method to fill in the parameters. Since this method uses a Date as a parameter, I don't need to fight with date formats, the JDBC driver handles that for me.

  • TS2634 Hi I have problem sum body still my Iphone 4s. what I can make ?

    Hi I have problem sum body still my Iphone 4s. what I can make ?

    This article shows what to do if your phone got stolen:
    http://support.apple.com/kb/ht2526

  • SQL Server 2014 - Columnstore Incorrect Results

    Hello,
    we are running into a problem with SQL Server 2014 and the columnstore index. We have a partitioned table with about 300 Million records in it. With SQL Server 2012 this has been in use without problems.
    Since we upgraded to SQL Server 2014, the exact same queries on exactly the same data return incorrect results. We can only bypass the problem by either dropping the CS Index or adding a maxdop = 1 query hint.
    I thought this was an old bug in SQL Server 2012? We have not installed the CU Pack 4 for SQL Server 2014, yet but will it solve the problem (assuming others have faced the same problem)
    We are running: Microsoft SQL Server 2014 Enterprise Edition - 12.0.2000.8 (X64) on a 2x6Core Machine
    Thanks in advance!

    SQL Server 2012 only featured non-clustered columnstore indexes which were separate structures.  Have you changed to a clustered columnstore (cs) index in SQL Server 2014?  (ie dropped your non-clustered cs, created a cs)
    There are a number of fixes that reference columnstore indexes in the current CUs (
    CU1,
    CU2, CU3,
    CU4 ), but none which sound exactly like your problem. 
    This sounds similar and is fixed in CU1.  You should review the CU documents yourself to see if any of them mention a similar problem and then consider applying the CU.  You might also try applying them to a test environment, or a temporary Azure
    VM for example to see if one of them solves your problem.
    If you can create a reliable "repro" of the problem, consider raising a
    connect item which is a Microsoft bug report.

  • ReportViewer using SQL Query error states: Incorrect syntax near ','.

    Hello Community
        Using Visual Studio 2008 and SQL Server 2008 I created a Windows Application
    that uses SQL Server Reporting Services.  The application uses ReportViewer and
    calls a method written using SQL query.
                1-First I created the form.
                2-Next I dragged the ReportViewer (Toolbox) and Table (from DataSource) onto the form.
    The problem is that when it reaches the last line of the SQL query (ie, da.Fill(ds, "TableOne");)
    the code fails stating the error message:
                "Incorrect syntax near ','."
         The following is the code behind the form containing the query:
            private void ReportPgm1_Load(object sender, EventArgs e)
                // TODO: This line of code loads data into the 'ReportDBDataSet.TableOne' table. You can move, or remove it, as needed.
                this.TableOneTableAdapter.Fill(this.ReportDBDataSet.TableOne);  
                reportViewer1.ProcessingMode = ProcessingMode.Local;
                LocalReport ReportOneLocalReport = reportViewer1.LocalReport;
                DataSet ds = new DataSet("ReportDBDataSet.TableOne");
                pgmReportOne(FromDate, ToDate,   ds);
                ReportDataSource ds = new ReportDataSource("ReportDBDataSet.TableOne");
                ds.Value = dataset.Tables["TableOne"];
                ReportOneLocalReport.DataSources.Clear();
                ReportOneLocalReport.DataSources.Add(ds);
                this.reportViewer1.RefreshReport();
            private void pgmReportOne(DateTime FromDate, DateTime ToDate, DataSet ds)
                SqlConnection connection = new SqlConnection("Data Source=ReportDBServer;Initial Catalog=ReportDB;Uid=sa;pwd=Password");
                string sqlReportOne = "Select ([InDate], [FirstName], [LastName], [AGe]" +
                                   "from TableOne";
                SqlCommand command = new SqlCommand(sqlReportONe, connection);
                command.Parameters.Add(new SqlParameter("paramFDate", FromDate));
                command.Parameters.Add(new SqlParameter("paramTDate", ToDate));
                SqlDataAdapter da = new SqlDataAdapter(command);
                da.Fill(ds, "TableOne");
        Why does the last line throw an error?
        Thank you
        Shabeaut

    --NOTE: The statement below cannot be run on SQL Server 2012
    --If you have an earlier version and can set the compatibility
    --level to 80, it can be run.
    SELECT sso.SpecialOfferID, Description, DiscountPct, ProductID
    FROM Sales.SpecialOffer sso,
    Sales.SpecialOfferProduct ssop
    WHERE sso.SpecialOfferID *= ssop.SpecialOfferID
    AND sso.SpecialOfferID != 1
    Hi Scott
    The *= is old syntax and not compatible with SQL Server 2012 (as stated in the comments). 
    You could do something like this instead
    SELECT sso.SpecialOfferID
    ,Description
    ,DiscountPct
    ,ProductID
    FROM Sales.SpecialOffer sso
    left outer join Sales.SpecialOfferProduct ssop on sso.SpecialOfferID = ssop.SpecialOfferID
    WHERE sso.SpecialOfferID != 1

  • Problem summing $-style digits

    When I open XLS file with russian finance style numbers (X XX,XX р.) it becomes in style X XX,XX Rbl
    It's not a problem, but some of cell become numbers like 10 000,00 Rbl but some cells becomes text "10 000,00 Rbl" and of course don't sum with number cells. So, imported Excel sheet shows different total value: correct in MS Excel and incorrect in Apple Numbers.
    Of course when I manually or via Find delete all "Rbl" it becomes "руб." but in some cells it becomes text again. After that I delete via Find command all "руб." and every cells become numbers and SUM formula works correctly but view of those cells stay the same! You know, because text "10 000 руб." after deleting becomes number 10 000 but because style is finance it becomes again 10 000 руб. but not text, numbers. So when I look on my table in Apple Numbers I cannot know is there some problem with results in formula until I take a calculator or open the same table in MS Excel and compare results!!!

    Hello
    some tracks
    Check which is the decimal separator defined in the System Preferences "International".
    Given your samples it would be the comma but I'm not sure.
    I don't use Microsoft products but one may guess that when the import parser meet a number formatted with a space (maybe a sticky one) between groups of three digits, it treats the number as a string, not as a number.
    A simple tip may help you to find the strings.
    Insert a column on the right of the values to check.
    Assuming that values are in column B insert a new column C and put the formula
    =B*1
    in every cells of this column.
    You will get a red triangle on the right of every string.
    You may use a more sophisticated formula:
    =IF(ISERROR(B*1),"string","")
    Yvan KOENIG (from FRANCE jeudi 22 novembre 2007 19:12:03)

  • SQL for summing weekly data

    Hi
    I have two tables which has date column and holding more than month data. I want to sum the weekly data starting Monday by combing two table . Can you any help me on to get the SQL for this.
    SQL> select * from ORCL_DATA_GROWTH;
    REPORT_DA DATAGROWTH                                                                                                             
    03-SEP-12       9.78                                                                                                             
    04-SEP-12       5.36                                                                                                             
    05-SEP-12       5.42                                                                                                             
    06-SEP-12      33.36                                                                                                             
    07-SEP-12       5.47                                                                                                             
    08-SEP-12        5.5                                                                                                             
    09-SEP-12        5.5                                                                                                             
    10-SEP-12       9.47                                                                                                             
    11-SEP-12       8.16                                                                                                             
    12-SEP-12      23.97                                                                                                             
    13-SEP-12      51.28                                                                                                             
    14-SEP-12      24.05                                                                                                             
    15-SEP-12      24.03                                                                                                             
    16-SEP-12      24.17                                                                                                             
    17-SEP-12      28.16                                                                                                             
    18-SEP-12      24.17                                                                                                             
    19-SEP-12      24.19                                                                                                             
    20-SEP-12      50.96                                                                                                             
    21-SEP-12      24.19   
    SQL> select * from ORCL_PURGING;
    REPORT_DA PURGING_SPACE FILE_SYSTEM                                                                                              
    01-OCT-12            18 /dborafiles/orac/ora_Test/oradata01                                                                     
    01-OCT-12             0 /dborafiles/orac/ora_Test/oradata05                                                                     
    02-OCT-12            55 /dborafiles/orac/ora_Test/oradata01                                                                     
    02-OCT-12             0 /dborafiles/orac/ora_Test/oradata05                                                                     
    03-OCT-12            21 /dborafiles/orac/ora_Test/oradata01                                                                     
    03-OCT-12             0 /dborafiles/orac/ora_Test/oradata05                                                                     
    04-OCT-12             0 /dborafiles/orac/ora_Test/oradata01                                                                     
    04-OCT-12             0 /dborafiles/orac/ora_Test/oradata05                                                                     
    05-OCT-12             0 /dborafiles/orac/ora_Test/oradata01                                                                     
    05-OCT-12             0 /dborafiles/orac/ora_Test/oradata05                                                                     
    06-OCT-12            70 /dborafiles/orac/ora_Test/oradata01                                                                     
    06-OCT-12             0 /dborafiles/orac/ora_Test/oradata05                                                                     
    07-OCT-12            21 /dborafiles/orac/ora_Test/oradata01                                                                     
    07-OCT-12             0 /dborafiles/orac/ora_Test/oradata05                                                                     
    08-OCT-12            21 /dborafiles/orac/ora_Test/oradata01                                                                     
    08-OCT-12             0 /dborafiles/orac/ora_Test/oradata05 Combining two table and daily out put sample below. But I want to have output by summing weekly value
    SQL> select a.report_date,sum(a.PURGING_SPACE) PURGING_SPACE,b.DATAGROWTH from ORCL_PURGING a ,ORCL_DATA_GROWTH b where a.report_date=b.report_date and a.report
    _date<=(sysdate) and a.report_date >=(sysdate-30) group by a.report_date,b.datagrowth order by a.report_date;
    REPORT_DA PURGING_SPACE DATAGROWTH
    19-SEP-12            77      24.19
    20-SEP-12             2      50.96
    21-SEP-12            47      24.19
    22-SEP-12            19      24.16
    23-SEP-12            22      24.05
    24-SEP-12            25      28.11
    25-SEP-12            43      24.08
    26-SEP-12            21      24.06
    27-SEP-12            22      50.86
    28-SEP-12            22      23.05
    29-SEP-12            22      23.27
    30-SEP-12            22      23.61
    01-OCT-12            18      28.67
    02-OCT-12            55      25.92
    03-OCT-12            21      23.38
    04-OCT-12             0      50.46
    05-OCT-12             0      23.62
    06-OCT-12            70      24.39
    07-OCT-12            21      24.53
    08-OCT-12            21      28.66
    09-OCT-12            51      24.41
    10-OCT-12            22      24.69
    11-OCT-12            23      50.72
    12-OCT-12            22      25.08
    13-OCT-12            25      25.57
    14-OCT-12            21      23.38
    15-OCT-12            22      27.77
    27 rows selected.                               Thanks in advance.
    Edited by: BluShadow on 18-Oct-2012 09:28
    added {noformat}{noformat} tags for readability.  Please read {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    user9256814 wrote:
    Hi
    This is my qery
    WITH purging_week AS
         SELECT TRUNC (report_date, 'IW')     AS report_week
         ,     SUM (purging_space)           AS total_purging_space -- same as in main query
         FROM      orcl_purging
         GROUP BY TRUNC (report_date, 'IW')
    ,     data_growth_week     AS
         SELECT TRUNC (report_date, 'IW')     AS report_week
         ,     SUM (datagrowth)           AS total_datagrowth
         FROM      orcl_data_growth
         GROUP BY TRUNC (report_date, 'IW')
    SELECT     COALESCE ( p.report_week
              , d.report_week
              )               AS report_week
    ,     p.total_purging_space
    ,     d.total_datagrowth
    FROM          purging_week     p
    FULL OUTER JOIN     data_growth_week d ON d.report_week = p.report_week
    ORDER BY report_week
    ;That's still hard to read.
    You may have noticed that this site normally compresses whitespace.
    Whenever you post formatted text (including, but not limited to, code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.  Blushadow probably won't do it for you every time you post a message.
    This is just one of the many things mentioned in the forum FAQ {message:id=9360002} that can help you get better answers sooner.
    Are you still having a problem?  Have you tried using in-line views?  If so, wouldn't it make more sense to post the code you're using, rather than some code you're not using?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Install Fails With SQL Server Version - Status: Incorrect

    Hi. I am working to install BPC 7 in a single server environment. During installation the setup diangostic detects a problem with [[Microsoft and 3rd Party Software]], below is what appears:
    X - SQL Server Version
    ____    OK - Required: 10.0.1600.22 or higher
    ____    OK - Currently: Not Installed
    ____    X   - Status: Incorrect
    X - SQL Reporting Services Server Version
    ____    OK - Required: 10.0.1600.22 or higher
    ____    OK - Currently: Not Installed
    ____    X   - Status: Incorrect
    X - OLAP Server Version
    ____    OK - Required: 10.0.1600.22 or higher
    ____    OK - Currently: Not Installed
    ____    X   - Status: Incorrect
    Under [[Computer Services Status]] SQL Server is alright:
    OK - MS SQL Server Service
    ____    OK - Required: Running
    ____    OK - Currently: Running
    ____    OK - Status: OK
    OK - MS SQL Server Agent Service
    ____    OK - Required: Running
    ____    OK - Currently: Running
    ____    OK - Status: OK
    OK - SQL Integrated Service
    ____    OK - Required: Running
    ____    OK - Currently: Running
    ____    OK - Status: OK
    OK - SQL Report Service
    ____    OK - Required: Running
    ____    OK - Currently: Running
    ____    OK - Status: OK
    OK - MS SQL Server OLAP Service
    ____    OK - Required: Running
    ____    OK - Currently: Running
    ____    OK - Status: OK
    What I've Checked so far:
    - Collation
    - Account for installation is SQL SysAdmin and a Windows account
    - Mixed mode authentication
    I should mention, this is a single server install on a 64 bit version of Windows, with 64 bit version of SQL.
    Any experience, ideas or suggestions are welcome.
    Joe
    Edited by: jwainz on Mar 29, 2010 5:55 PM

    I think the clearest statement about this is on page 11 of the Master Guide (SAP BPC 7.0 M Master Guide at [http://service.sap.com/instguidesEPM-BPC]).
    Look at the rows for OLAP Server and Microsoft SQL Server.  In each of those, you wil find this statement:
    "Can be 64‒bit when separate from Application/web services"
    On page 10 in the Installation Guide, for look at the rows for Application server Web Server.  The prerequisites are as follow:
    App Server:
    Windows Server 2003 or Windows Server 2003 R2 Standard or Enterprise Edition SP2 (32-bit) configured with NTFS, set to English (United States)
    Web Server:
    Windows Server 2003 or Windows Server 2003 R2 Standard or Enterprise Edition SP2 (32-bit) configured with NTFS
    Finally, the PAM is a bit confusing.  For product SAP BPC 7.0 FOR MICROSOFT, click on the tab Operating Systems and then click on the tab BPC Server.  That is the software that you install for the Application Server and the Web Server server types.  The Operating System Version listed is WINDOWS SERVER 2003/IA32 32BIT

  • SQL The Parameter is incorrect

    Hi!
    I have installed the latest SQL MP (6.5.4.0) at a Swedish customer that before have a lot of running script errors that was caused by the SQL MP difference scripts. Now we only get one of this alarm left. The alarm is "Operations manager failed to start
    a process" from many of the SQL servers. We get two difference text descriptions:
    1) The text says that the "The parameter is incorrect" the workingflow is from
    Microsoft.SQLServer.2012.DBEngine.ServiceMonitor
    Microsoft.SQLServer.2008.Database.ServiceMonitor
    2) The text says that the "Processes is ending with 0" the workingflow is from
    Microsoft.SQLServer.2012.Database.Configuration.TomPagrDetection
    Microsoft.SQLServer.2012.DBEngineDiscoveryRule.Server
    //Mats A

    Hi Mats,
    Please first update the Monitor Agent:
    Update Rollup for Microsoft Monitoring Agent (KB 3032946)
    https://support.microsoft.com/en-us/kb/3032946
    Is there any event log error? Please also help capture a screenshot.
    Btw, did you see any performance issue on the mointor servers? If so, please increase the desktop heap on the mointor servers.
    1. Open regedit and take a backup.
    2. Go to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows. Export it for backup purpose.
    3. The default data for this registry value will look something like the following (all on one line):
    %SystemRoot%\system32\csrss.exe ObjectDirectory=\Windows SharedSection=1024,20480,768 Windows=On SubSystemType=Windows ServerDll=basesrv,1 ServerDll=winsrv:UserServerDllInitialization,3 ServerDll=sxssrv,4 ProfileControl=Off MaxRequestThreads=16
    4. Modify the SharedSection to SharedSection=1024,20480,1536
    5. Save and reboot the machine.
    Thanks.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Sql problem, pivot question?

    Hi guys,
    I have an interesting problem and do not manage to find a sollution.
    I need to create a report, and we call it variance/trending report. let me explain.
    I have a table that holds all employess with their salaries, every month.
    currenly my selects gets all employess with their salaries from current and previous month. and the result looks like:
    Employee_iD| Salary| month
    1          |500   |   C
    2          |100   |   P
    1          |650   |   P
    3          |100   |   p
    3           |180   |   C
    how can I do my select so I can see the result, in different columns, in a manner in which I can compare the salaries between them (from current and previous month):
    Employe_iD| current_month| previous_month | variance
    1        |500                 | 650                 | -150
    2        |                      | 100                 |
    3        |180                 |100                   |80you can see that C, measn current month, and P measn previous month.
    I think I will have data in my select for both, previous and current. If not, I will treat it as zero.
    I gave a simple exemple . My select is a little more complex.
    any help is appreciated.
    Thanks

    May be..
    SQL> WITH tbl AS (SELECT 1 empid,500 sal,'C' mon FROM DUAL UNION ALL
      2               SELECT 2 empid,100 sal,'P' mon FROM DUAL UNION ALL
      3               SELECT 1 empid,650 sal,'P' mon FROM DUAL UNION ALL
      4               SELECT 3 empid,100 sal,'P' mon FROM DUAL UNION ALL
      5               SELECT 3 empid,180 sal,'C' mon FROM DUAL
      6               )
      7  SELECT empid,NVL(MAX(DECODE(mon,'P',sal)),0) previous_sal
      8              ,NVL(MAX(DECODE(mon,'C',sal)),0) current_sal
      9              ,NVL(MAX(DECODE(mon,'P',sal)),0)- NVL(MAX(DECODE(mon,'C',sal)),0)
    10                var
    11  FROM tbl
    12  GROUP BY empid          
    13               ;
         EMPID PREVIOUS_SAL CURRENT_SAL        VAR
             1          650         500        150
             2          100           0        100
             3          100         180        -80

  • PL/SQL problem in portal

    hello all,
    PROBLEM :
    I followed this thread Copying data from one field to another on a form
    but unfortunately..encountered with d following error...
    Any PL/SQL coding is throwing such errors on my portal..
    I have to install any additional tools or configure something..( I done executed the provsyns.sql for myschema)
    Someone please suggest me..
    ERROR :
    Internal error (WWC-00006)
    An unexpected error occurred: ORA-01001: invalid cursor (WWV-16016)
    Error displaying form : ORA-01001: invalid cursor (WWV-16408)
    Error running user PL/SQL code: ORA-01001: invalid cursor (WWV-16403)
    ORA-06550: line 5, column 7:
    PLS-00201: identifier 'P_SESSION.GET_VALUE_AS_VARCHAR2' must be declared
    ORA-06550: line 5, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 8, column 9:
    PLS-00201: identifier 'P_SESSION.GET_VALUE_AS_VARCHAR2' must be declared
    ORA-06550: line 8, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 11, column 1:
    PLS-00201: identifier 'P_SESSION.SET_VALUE' must be declared
    ORA-06550: line 11, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 15, column 1:
    PLS-00201: identifi (WWV-11230)
    Failed to parse as PORTAL_PUBLIC - BEGIN declare
    id varchar2(20);
    name varchar2(20);
    begin
    id := p_session.get_value_as_VARCHAR2(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'EMP_ID');
    name := p_session.get_value_as_VARCHAR2(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'EMP_NAME');
    p_session.set_value(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'ID',
    p_value => id);
    p_session.set_value(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'NAME',
    p_value => name);
    end; END; (WWV-08300)
    The preference path does not exist: ORACLE.WEBVIEW.PARAMETERS.1668713167 (WWC-51000)
    Many Thanks In Advance :-)

    hi Pappu
    if you have used the same exact code as given in the message you have mentioned, then please correct one variable's name. the reply I gave in that thread has a typo. in suggesting a solution to that question, I had tried it with a different set of variables on my system and in replying back, i mistakenly left one such variable in that thread.
    try it and see if you still get errors.
    AMN
    declare
    v_address1 varchar2(20);
    begin
    v_address1 := p_session.get_value_as_VARCHAR2(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'A_ADDRESS1');
    p_session.set_value(
    p_block_name => 'DEFAULT',
    p_attribute_name => 'A_LOCATION1',
    p_value => v_address1);
    end;

  • PL/SQL- Problem in creating a partitioned fact table using select as syntax

    Hi All,
    I am trying to create a clone(mdccma.fact_pax_bkng_t) of existing fact table (mdccma.fact_pax_bkng) using dynamic pl/sql. However, pl/sql anonymous block errors out with following error:
    SQL> Connected.
    SQL> SQL> DECLARE
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 1608
    ORA-06512: at "SYS.DBMS_SQL", line 33
    ORA-06512: at line 50
    Here is pl/sql block:
    -- CREATING FPB_T
    DECLARE
    v_owner VARCHAR2(32) := 'MDCCMA';
    v_table_original VARCHAR2(32) := 'FACT_PAX_BKNG';
    v_table VARCHAR2(32) := 'FACT_PAX_BKNG_T';
    v_tblspc VARCHAR2(32) := v_owner||'_DATA';
    CURSOR c_parts IS SELECT TABLESPACE_NAME, PARTITION_NAME,HIGH_VALUE, ROW_NUMBER() OVER (ORDER BY PARTITION_NAME) AS ROWNUMBER
    FROM USER_TAB_PARTITIONS
    WHERE TABLE_NAME = v_table_original
    ORDER BY PARTITION_NAME;
    v_cmd CLOB := EMPTY_CLOB();
    v_cmd3 varchar2(300) := 'CREATE TABLE ' ||v_owner||'.'||v_table||' TABLESPACE '||v_tblspc
    ||' NOLOGGING PARTITION BY RANGE'||'(' ||'SNAPSHOT_DTM '||')' ||'(';
    v_part VARCHAR2(32);
    v_tblspc_name VARCHAR2(32);
    v_row number;
    v_value LONG;
    v_tmp varchar2(20000);
    v_cur INTEGER;
    v_ret NUMBER;
    v_sql DBMS_SQL.VARCHAR2S;
    v_upperbound NUMBER;
    BEGIN
    v_cmd := v_cmd3;
    OPEN c_parts;
    FETCH c_parts INTO v_tblspc_name, v_part,v_value, v_row;
    WHILE c_parts%FOUND
    LOOP
    IF (v_row = 1) THEN
    v_tmp := ' PARTITION '||v_part||' VALUES LESS THAN ' ||'('|| v_value||')'||' NOLOGGING TABLESPACE '||v_tblspc_name;
    ELSE
    v_tmp := ', PARTITION '||v_part||' VALUES LESS THAN ' ||'('|| v_value||')'||' NOLOGGING TABLESPACE '||v_tblspc_name;
    END IF;
    v_cmd := v_cmd || v_tmp;
    -- DBMS_OUTPUT.PUT_LINE(v_cmd);
    FETCH c_parts INTO v_tblspc_name, v_part,v_value, v_row;
    END LOOP;
    -- DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_cmd));
    v_cmd := v_cmd||')'||' AS SELECT ' || '*'||' FROM ' || v_owner||'.'|| v_table_original ||' WHERE '||'1'||'='||'2'||';';
    v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_cmd)/256);
    FOR i IN 1..v_upperbound
    LOOP
    v_sql(i) := DBMS_LOB.SUBSTR(v_cmd
    ,256 -- amount
    ,((i-1)*256)+1 -- offset
    END LOOP;
    v_cur := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
    v_ret := DBMS_SQL.EXECUTE(v_cur);
    CLOSE c_parts;
    DBMS_OUTPUT.PUT_LINE(v_cmd);
    -- EXECUTE IMMEDIATE v_cmd ;
    END;
    The above pl/sql creates a DDL for partitioned fact table(new) based on an existing fact table and get executes through CLOB.
    Please look into the issue and let me know any changes or modifications/suggestions that are required to fix the issue. Any help is appreciated.
    Thank You,
    Sudheer

    Think this is your problem:
    v_cmd := v_cmd||')'||' AS SELECT ' || '*'||' FROM ' || v_owner||'.'|| v_table_original ||' WHERE '||'1'||'='||'2'||';';Remove the SQL terminator ';' ... dynamic SQL doesn't require it, try this instead:
    v_cmd := v_cmd||')'||' AS SELECT ' || '*'||' FROM ' || v_owner||'.'|| v_table_original ||' WHERE '||'1'||'='||'2';Thanks
    Paul

  • SQL problem

    I've got a problem with a servlet I'm writing. Here's a code snippet:
    if(operation.equals("Lookup details"))
              {     //get customer details
                   String Hnum = req.getParameter("HouseNum");
                   String Pcode = req.getParameter("PostCode");
                  String sql = "SELECT * FROM Customer WHERE house_num = " Hnum " AND postcode = '" Pcode "'";
                  String url = "jdbc:pointbase:server://localhost:9092/projectdb";
                  Connection con;
                  Statement stmt;
                  ResultSet rs;
                   try {
                        Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
                   catch(ClassNotFoundException ex) {
                        out.println("Failed to find driver");
                   try {
                        con = DriverManager.getConnection(url, "PBPUBLIC", "PBPUBLIC");
                        stmt = con.createStatement();
                        //execute query
                        rs = stmt.executeQuery(sql);
                   catch(SQLException ex) {
                        out.println("SQL Exception");
                        out.println("" + ex);
              }When it comes to actually executing the sql command I get the following error:
    SQL Exception
    java.sql.SQLException: Expected to find "end of SQL command" instead found "POSTCODE" at position 46.
    I can't quite see whats wrong with my SQL string, its probably something simple tho. Any ideas?

    For sure (200%) your request does not contain HouseNum parameter.
    You should check presence of HouseNum parameter for instance like:
    String hnum=req.getParameter("HouseNum");
    if(hnum==null || hnum.trim().length()==0)
       //do something here - for instance put default HouseNum value like:
       hnum="1"
    }

Maybe you are looking for

  • How do I add remember password for a new web site?

    I am trying to have Firefox remember a password for a specific website. I go to Options, then Security but have great difficulty thereafter. Can you give me specific data to enter, where to enter it and how to save the password? Thank you Al Landry

  • DVI to s-video adapter altering laptop display after connection with TV

    Greetings, I recently got my MacBook Pro to display on my TV via the dvi to s-video adapter (also connected stereo sound). Everything works great, but ... after I disconnect the windows on several of my programs are altered (stretched, shortened, oft

  • Down payments - Delivery related billing

    Hi Guys, I am an FI guy. I have a question in SD billing. Is it possible to collect and clear down payments in delivery related billing. If so, Can you please elaborate the steps in doing so. Thanks, Satya

  • DDGenerator.generateDDs(projectDefinition(), ddDefinitions);

    Pls help I'm using JDk1.4 on windows NT, trying to generate my deployment descriptors with the DDGenerator.generateDDs(projectDefinition(), ddDefinitions); class and methods. Last time we used Toplink 353, and it works great. Has something changed, c

  • One Infopath 2013 custom list be access by 2 workflows

    When accessing an InfoPath 2013 form that accesses a custom list, I have found that I need to split up an existing workflow 2013 into 2 workflows.  This is due to the workflow 2013 does not contain some features that workflow 2010 contains. Thus I ha