Error in the simple Query

Dear Experts,
Not able to Execute this simple query :
Select T1.JobID , T1.BudgetValue,T1.ActualValue FROM [dbo].[Enprise_JobCost_ActualBudgetView] T1 WHERE T1.TransType = '[%0]'
Regards

Hello,
View - A View in simple terms is a subset of a 'virtual table. It can be used to retrieve data from the tables, Insert, Update or Delete from the tables. The Results of using View are not permanently  stored in the database.
Stored Procedure -  A stored procedure is a group of SQL statements which can be stored into the database and can be shared over the netwrok with different users.
http://www.geekinterview.com/question_details/65914
Better make a UDT for your requirement.
Thanks
Manvendra Singh Niranjan

Similar Messages

  • Two or more productid will be accquired by same customerid, by same shipvia, on the same day of the week of shipped date. i want the simple query for this.

    consider this situation,
     Two or more productid will be accquired by same customerid, by same shipvia, on the same  day of the week of shipped date. i want the simple query for this.
    my tables are  from northwind:
    [orders] = OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry.
    [orders details] = OrderID, ProductID, UnitPrice, Quantity, Discount.
    i tried some but it is not exact, it gives wrong result.
    select pd.CustomerID,pd.ProductID, pd.no_of_time_purchased, sd.ShipVia, sd.same_ship_count, shipped_day from
    select ProductID,o.CustomerID,COUNT(productid) as no_of_time_purchased
    from orders o join [Order Details] od on o.OrderID=od.OrderID group by ProductID,o.CustomerID
    having count(od.ProductID) >1) pd
    join
    (select OrderID,customerid, shipvia, count(shipvia)as same_ship_count, DATENAME(DW,ShippedDate)as shipped_day from orders
    group by customerid, ShipVia, ShippedDate having COUNT(ShipVia) > 1 ) sd
    on sd.CustomerID=pd.CustomerID

    Hi,
    I think I have a solution that will at least give you a clue how to go about it. I have simplified the tables you mentioned and created them as temporary tables on my side, with some fake data to test with. I have incldued the generation of these temporary
    tables for your review.
    In my example I have included:
    1. A customer which has purchased the same product on the same day, using the same ship 3 times,
    2. Another example the same as the first but the third purchase was on a different day
    3. Another example the same as the first but the third purchase was a different product
    4. Another example the same as the first but the third purchase was using a different "ShipVia".
    You should be able to see that by grouping on all of the columns that you wich to return, you should not need to perform any subselects.
    Please let me know if I have missed any requirements.
    Hope this helps:
    CREATE TABLE #ORDERS
     OrderID INT,
     CustomerID INT,
     OrderDate DATETIME,
     ShipVia VARCHAR(5)
    CREATE TABLE #ORDERS_DETAILS
     OrderID INT,
     ProductID INT,
    INSERT INTO #ORDERS
    VALUES
    (1, 1, GETDATE(), 'ABC'),
    (2, 1, GETDATE(), 'ABC'),
    (3, 1, GETDATE(), 'ABC'),
    (4, 2, GETDATE() - 4, 'DEF'),
    (5, 2, GETDATE() - 4, 'DEF'),
    (6, 2, GETDATE() - 5, 'DEF'),
    (7, 3, GETDATE() - 10, 'GHI'),
    (8, 3, GETDATE() - 10, 'GHI'),
    (9, 3, GETDATE() - 10, 'GHI'),
    (10, 4, GETDATE() - 10, 'JKL'),
    (11, 4, GETDATE() - 10, 'JKL'),
    (12, 4, GETDATE() - 10, 'MNO')
    INSERT INTO #ORDERS_DETAILS
    VALUES
    (1, 1),
    (2, 1),
    (3, 1),
    (4, 2),
    (5, 2),
    (6, 2),
    (7, 3),
    (8, 3),
    (9, 4),
    (10, 5),
    (11, 5),
    (12, 5)
    SELECT * FROM #ORDERS
    SELECT * FROM #ORDERS_DETAILS
    SELECT
     O.CustomerID,
     OD.ProductID,
     O.ShipVia,
     COUNT(O.ShipVia),
     DATENAME(DW, O.OrderDate) AS [Shipped Day]
    FROM #ORDERS O
    JOIN #ORDERS_DETAILS OD ON O.orderID = OD.OrderID
    GROUP BY OD.ProductID, O.CustomerID, O.ShipVia, DATENAME(DW, O.OrderDate) HAVING COUNT(OD.ProductID) > 1
    DROP TABLE #ORDERS
    DROP TABLE #ORDERS_DETAILS

  • Error in the Dynamic query in AME

    Hi Experts,
    I am using the below query but i am facing the error "Ensure the query selects exactly 1 column" in AME Approval group under Dynamic query.
    But the query returns only one column when i ran in toad.
    select 'person_id:'||a.person_id  from
    (SELECT to_number(EXTRACT(column_value,'/e/text()')) person_id
    from (select (XXSYK_GET_PERSON_ID(:transactionId)) col1 from dual) x,
    TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE('<ROW><e>'||REPLACE(col1,',','</e><e>')||'</e></ROW>'),'//e')))
    )A
    Thanks,
    Sadeesh

    Thanks !!!!

  • ByteArray error in a simple query.

    I've inherited an application that I'm working on migrating
    to CF7. It works on the testing server, but does not work on the
    production server, so I suspect that this is a server configuration
    issue. CF product version: 7,0,2,142559
    The problem:
    I'm looping through a query, running a query on each row, and
    trying to display the results. The subquery keeps throwing a
    "ByteArray objects cannot be converted to strings." error. This
    only happens on the new production server (which has been causing
    problems anyway). I've tried using CFQUERYPARAM, but that throws a
    "Invalid data [B@1bef393 for CFSQLTYPE CF_SQL_CHAR" error. The
    database is MS SQL, and the ClassKey column is a uniqueidentifier.
    I've been working on this for several hours, now, so any
    helpful tips -- or even better, solutions! -- would be terrific.

    Never mind; it's a database issue.

  • Error in the SAP query for Assets?

    Hi,
    I am trying to make 2 queries related to the assets but it is not selecting the data may I know why and where I am doing wrong.
    I have joined the tables ANLA, ANLC, ANLP and ANLB.
    Fields that have been selected are as follows:
    Asset Subnumber ANLA-ANLN2
    Asset Class ANLA-ANLKL
    Asset description ANLA-TXT50
    Company Code ANLA-BUKRS
    Serial number ANLA-SERNR
    Main Asset Number ANLA-ANLN1
    Asset Subnumber ANLA-ANLN2
    Asset Class ANLA-ANLKL
    Asset description ANLA-TXT50
    Company Code ANLA-BUKRS
    Serial number ANLA-SERNR
    Main Asset Number ANLA-ANLN1
    Fiscal Year ANLC-GJAHR
    Ordinary depreciation posted in the current year ANLC-NAFAG
    Planned ordinary depreciation for the year ANLC-NAFAP
    Accumulated ordinary depreciation ANLC-KNAFA
    Cumulative acquisition and production costs ANLC-KANSW
    Asset Subnumber ANLA-ANLN2
    Asset Class ANLA-ANLKL
    Asset description ANLA-TXT50
    Company Code ANLA-BUKRS
    Serial number ANLA-SERNR
    Main Asset Number ANLA-ANLN1
    Fiscal Year ANLC-GJAHR
    Ordinary depreciation posted in the current year ANLC-NAFAG
    Planned ordinary depreciation for the year ANLC-NAFAP
    Accumulated ordinary depreciation ANLC-KNAFA
    Cumulative acquisition and production costs ANLC-KANSW
    Transactions for the year affecting asset values ANLP-ANSWL
    Planned ordinary depreciation for the year ANLP-NAFAP
    Ordinary depreciation posted in the current year ANLP-NAFAG
    Ordinary depreciation to be posted ANLP-NAFAZ
    Asset acquisition year (currently not used) ANLP-ZUJHR
    Depreciation calculation period ANLP-PERAF
    Original useful life in years ANLB-NDURJ
    Depreciation key ANLB-AFASL
    Please tell me where SAP query is no working and what shall I do to make it work.
    Thanks and regards
    Nitin

    Thanks !!!!

  • TOPLINK-6119 ERROR for the following query,

    any ideas as how to modify or make the query work? thanks,
    Query:
    ====
    ReadAllQuery query5 = new ReadAllQuery();
    query5.setReferenceClass( Instrument.class );
    query5.setSelectionCriteria( new ExpressionBuilder().get( "shortName" ).equal( shortName ) );
    query5.addBatchReadAttribute( query5.getExpressionBuilder().anyOf( "customFields" )
    .get( "stringValue" ).equal( "XYZ987" ) );
    Exception stack
    ===========
    Database exception: Exception [TOPLINK-6119] (Oracle TopLink - 10g Release 3 (10.1.3.3.0) (Build 070620)): oracle.toplink.exceptions.QueryException
    Exception Description: The join expression
    Relation operator =
    Query Key stringValue
    Query Key customFields
    Base QUERY OBJECT
    Constant XYZ987 is not valid, or for a mapping type that does not support joining.
    Query: ReadAllQuery(com.integral.finance.instrument.Instrument).
         at com.integral.persistence.PersistenceFactory.handleException(PersistenceFactory.java:793)
         at oracle.toplink.publicinterface.Session.handleException(Session.java:1951)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1021)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:950)
         at com.integral.finance.instrument.test.InstrumentCustomFieldPTestC.testInstrument(InstrumentCustomFieldPTestC.java:588)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at junit.framework.TestCase.runTest(TestCase.java:154)
         at junit.framework.TestCase.runBare(TestCase.java:127)
         at junit.framework.TestResult$1.protect(TestResult.java:106)
         at junit.framework.TestResult.runProtected(TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:118)
         at junit.framework.TestSuite.runTest(TestSuite.java:208)
         at junit.framework.TestSuite.run(TestSuite.java:203)
         at junit.textui.TestRunner.doRun(TestRunner.java:116)
         at com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:69)
         at junit.textui.TestRunner.doRun(TestRunner.java:109)
         at com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:24)
         at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
         at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

    Hello,
    Your are adding a selection criteria through the addBatchReadAttribute api which isn't allowed. It is expecting only a query key type expression.
    Try:
      ReadAllQuery query5 = new ReadAllQuery();
      query5.setReferenceClass( Instrument.class );
      ExpressionBuilder exb = query5.getExpressionBuilder();
      Expression batchExpression = exb.anyOf( "customFields" );
      Expression expression = exb.get( "shortName" ).equal( shortName );
      expression = expression.and( batchExpression.get( "stringValue" ).equal ("XYZ987") );
      query5.setSelectionCriteria( expression );
      query5.addBatchReadAttribute( batchExpression );This will return all Instrument objects with the require shortName and having a customField with the stringName of "XYZ987". It will use batching to return all referenced customFields (not just the ones with a stringName of "XYZ987").
    Best Regards,
    Chris

  • Simple query ... syntax error ?

    What is wrong with this simple sql statement ?
    SELECT Caseid
    FROM (SELECT DISTINCT Caseid, userid FROM Atts)
    I get this error
    Server: Msg 170, Level 15, State 1, Line 2
    Line 2: Incorrect syntax near ')'.

    In this case, it could go either way. Because the derived
    table is
    performing the select distinct anyway, the execution plans
    would be similar,
    but you'd see one extra step for selecting all rows from the
    derived table.
    Notice that the derived table has distinct caseid, userid,
    but the main
    query only selects caseid. If the extra IO required to
    transmit the
    unwanted userid column is more expensive than the extra step
    required to
    select just the caseid column out of the derived table, then
    the derived
    table is the better choice.
    In any case, the simpler query is usually the better option.
    Unless he
    actually wants a duplicate caseid for each userid, but not
    the userid
    itself, plain ol' SELECT DISTINCT makes more sense.
    "bregent" <[email protected]> wrote in
    message
    news:ejaad1$k2u$[email protected]..
    > >On the contrary, subqueries in the FROM clause are
    quite useful and can
    > >in
    > >the right situations perform much better than
    alternative queries.
    >
    > Ah, as usual you are correct. It looks like he forgot to
    add a DT alias
    > name
    > at the end of the statement which is causing the error.
    But in any case, a
    > simple select distinct would yield the same results and
    performance,
    > correct?
    >

  • Getting the MDX query select error when running a webi report on BI query

    Getting the following error when running a webi report on BI query :
    A database error occured. The database error text is: The MDX query SELECT  { [Measures].[D8JBFK099LLUVNLO7JY49FJKU] }  ON COLUMNS , NON EMPTY [ZCOMPCODE].[LEVEL01].MEMBERS ON ROWS FROM [ZTEST_CUB/REP_20100723200521]  failed to execute with the error Unknown error. (WIS 10901).
    I have gone through many threads related to this error. But not able find the steps to follow for resoultion.
    Please help in this regard.
    Thanks,
    Jeethender

    The Fix Pack is also for Client Tools--it is a separate download.  Please see the text below for ADAPT01255422
    ADAPT01255422
    Description:
    Web Intelligence generates an incorrect MDX statement when a characteristic and a prompt are used.
    The following database error happens: "The MDX query ... failed to execute with the error
    Unknown error (WIS 10901)."
    New Behavior:
    This problem is resolved.
    This information is also available in the Fixed Issues document for any Fix Pack greater than 2.2.

  • Case expression error with a select query in the condition

    Consider the two query below:
    1. The first one use a case expression :
    select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual
    2. The equivalent with a decode expression:
    select
    decode(sign(3-(select 1 from dual)*2),1,1,0) from dual
    The first query return an ORA-00905 error but not the second one. It seems that the arithmetic operation (select 1 from dual)*2 cause the error. The folowing query doesn't return this error:
    select case when 3 > (select 2 from dual) then 1 else 0 end from dual
    I run the test with Oracle 8.1.7.3 Enterprise Edition. Is it a known bug ?
    Thomas

    ora8174>select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual;
    select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual
    ERROR at line 1:
    ORA-00905: missing keyword
    ora8174>select case when 3 > cast((select 1 from dual)*2 as number) then 1 else 0 end from dual;
    CASEWHEN3>CAST((SELECT1FROMDUAL)*2ASNUMBER)THEN1ELSE0END
                                                           1
    1 row selected.
    ora8174>select case when 3 > to_number((select 1 from dual)*2) then 1 else 0 end from dual;
    CASEWHEN3>TO_NUMBER((SELECT1FROMDUAL)*2)THEN1ELSE0END
                                                        1
    1 row selected.
    ora8174>@connect
    Connected.
    ora9204>select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual;
    CASEWHEN3>(SELECT1FROMDUAL)*2THEN1ELSE0END
                                             1
    1 row selected.

  • Syntax Error in the Query

    Dear All,
    Please tell me syntax error in the below query. When I'm going to write numeric number in this filed "$[ OVPM.DocNUm ]". It's working fine. But when I'm writing this it give me error.Please clear me where am wrong????I
    SELECT T0.[AcctNum] FROM VPM1 T0 WHERE T0.[DocNum] =$ [OVPM.DocNUm ]
    Regards
    Edited by: Anwar Ali Sohail on Sep 27, 2011 11:43 AM

    HI
    Try This
    SELECT T0.[CheckNum] FROM VPM1 T0  INNER JOIN OVPM T1 ON T0.DocNum = T1.DocEntry WHERE T0.[DocNum] = $[OVPM.DocNum]
    OR
    SELECT T0.[AcctNum] FROM VPM1 T0  INNER JOIN OVPM T1 ON T0.DocNum = T1.DocEntry WHERE T0.[DocNum] = $[OVPM.DocNum]
    Edited by: kambadasan on Sep 27, 2011 4:26 PM

  • Datatype : 25 not supported error while saving Logical Query in BIP Dataset

    Hi All,
    I have created a nested logical Query in OBIEE Publisher Datamodel using parameters.
    Here is the simple query :
    Select name, revenue, date from
    select "SubjectAreaName"."TableName"."Name" name,
    case when :Date > date '2012-01-01' then "SubjectAreaName"."TableName"."Revenue" else NULL end Revenue,
    date date
    from
    "SubjectAreaName"
    where
    date = :Date
    ) T1
    Note - :Date is the parameter. When I try saving this dataset as-is, it throws me Datatype : 25 not supported error. But, when i replace the parameter :Date with actual date, then the query works. Also, the inner query works with or without parameters. The issue arises when I use the outer query and the parameters.
    Please let me know if you have come across such a problem ?
    Any help on this regard would be highly appreciated.
    Thanks
    Swarna

    ya i can understand we wont do the sql logic at the data model part as some time performance issue may come when comparaed to sql run in package and sql running in data model . so i have mostly done using package and i will just do select * from table in the data set of data model so i didn't face any issue's like this .
    once check this tutorial may be you already
    i use to create parameters like this i didn't face any issue
    SELECT * from TEST where ID=:p_id
    http://st-curriculum.oracle.com/obe/fmw/bi/bip/bip11g/gettingstarted/gettingstarted.htm

  • Testing an ISA Server Rule, the recursive query to other DNS Servers test fails

    Hello,
    I am trying to configure the following infrastructure with ISA Server 2006 and two W2003 servers (called "Server1" and "Server2") . "Server1" is a domain controller, and in
    "Server2" is the ISA Server installed, which also has
    attached two network Ethernet cards, one called "Internal Ethernet Card", and the other one called
    "External Ethernet Card".
    The infrastructure would be:  "Internal Ethernet Card"---- ISA Server ----"External Ethernet Card"---"Router"----"Internet"
    "Internal Ethernet Card" manages the internal package traffic of the infrastructure, the network segment which belongs is isolated from what we could called the Outbound traffic, which is linked to a router. "Internal Ethernet Card" it`s
    a virtual network.
    "Internal Ethernet Card" feature configuration is the following:
    - IP address: 192.168.3.3
    - Subnet Mask: 255.255.255.0
    - DHCP Enabled: No
    - DNS Server: 192.168.3.1 (Must point to the DC "Server1" which has the DNS Service installed)
    - Default Gateway:  None  (because doesnt point to outside)
    - Primary WINS Server: 192.168.3.1  
    The "External Ethernet Card" provides, the outbound connection, and this card is connected to the physical router.
    It`s feature configuration is the following:
    - IP address: 192.168.1.50
    - Subnet Mask: 255.255.255.0
    - DHCP Enabled: No
    - Default Gateway: 192.168.1.1
    - DNS Servers: 192.168.3.1 (Must point to the DC "Server1" which has the DNS Service installed)
    After configuring the network cards, I create the following rule in the ISA Server to allow the traffic towards outside from the server and the clients which have joined to the domain:
    Action: Allow.  Protocol: DNS.  From:"Server2".  To : External.  Condition: All Users
    After applying the changes to update the configuration, I enter in the Dns Server of "Server1" and in the "Monitoring" tab, I run a "recursive query to other DNS Servers" but fails.
    Only works the "simple query against this DNS Server".
    I don`t know why fails, but I`m stucked on this issue, because in the "Server1" DNS Server, in the "domain forward IP address list", I have added two DNS addresses which work OK.
    I would appreciate some help to solve this issue.
    Thanks
    Regards 

    Hello Ms. Long, 
    Yes, you are right. In the Server1 is configured the DNS server, to use forwarders whose are set in the field "Selected domain`s forwarder IP address list", two DNS address numbers obtained from "Open DNS", which work well.
    There is no DNS Server linked to the External NIC.
    The Server1 belongs to a private network configured as "VMnet3", which it is set as follows:
    IP address: 192.168.3.1
    Subnet Mask: 255.255.255.0
    Default Gateway: 192.168.3.3
    DNS Server: 192.168.3.1
    I have tried to test your suggested idea:
    > set d2
    > google.com
    Server:  srv-dcfs-01.dominio.local
    Address:  192.168.3.1
    SendRequest(), len 42
        HEADER:
            opcode = QUERY, id = 2, rcode = NOERROR
            header flags:  query, want recursion
            questions = 1,  answers = 0,  authority records = 0,  additional = 0
        QUESTIONS:
            google.com.dominio.local, type = A, class = IN
    Got answer (113 bytes):
        HEADER:
            opcode = QUERY, id = 2, rcode = NXDOMAIN
            header flags:  response, auth. answer, want recursion, recursion avail.
            questions = 1,  answers = 0,  authority records = 1,  additional = 0
        QUESTIONS:
            google.com.dominio.local, type = A, class = IN
        AUTHORITY RECORDS:
        ->  dominio.local
            type = SOA, class = IN, dlen = 46
            ttl = 3600 (1 hour)
            primary name server = srv-dcfs-01.dominio.local
            responsible mail addr = hostmaster
            serial  = 41
            refresh = 900 (15 mins)
            retry   = 600 (10 mins)
            expire  = 86400 (1 day)
            default TTL = 3600 (1 hour)
    SendRequest(), len 28
        HEADER:
            opcode = QUERY, id = 3, rcode = NOERROR
            header flags:  query, want recursion
            questions = 1,  answers = 0,  authority records = 0,  additional = 0
        QUESTIONS:
            google.com, type = A, class = IN
    DNS request timed out.
        timeout was 2 seconds.
    timeout (2 secs)
    SendRequest failed
    *** Request to srv-dcfs-01.dominio.local timed-out
    As you can see highlighted in bold, the problem remains in the "recursive query to other DNS Servers" check.
    Maybe is better to put the issue on the "Windows Server General Forum" , because the issue has not nothing in common with the ISA Server, dont you?
    Thanks
    Best regards

  • Bica: change the query cause error in the pas model

    Dear  friends,
    We have very simple scenario: one query 'SSM_SQL_KPI_MAY'' for feeding  the pas model- 2 demensions and 2 measures. With this query I load the schema and data to the pas model.Everithing was fine. After that we added new  dimension to the query.Ichanged the  existing query and load the data with bica.But when I try to open the model I get the next  error every time
    DAT316:
    No internal Dimenson unique name to position cache exists for 'EZOR_KEY' on Linkid 'BI' Cube 'SSMKPI/SSM_SQL_KPI_MAY'
    We try to resolve the issue by deleting data and schema but every time I get the same error.
    How is it possible to resolve this issue?
    What is a best practice in the case of changing queries working with bica?
    Thanks.
    Best regards,Orit.

    Dear Orit,
    Keep in mind that dimensions provided by a BICA query connection must have a HIERARCHY associated to the base characteristic in BW. PAS uses this hierarchy to define the "Result" (rollup) levels of the dimension. Check your BW query and verifiy that all the included dimensions have associated hierarchies in use. I'm guessing this is the issue with your new dimension.
    You can also check the dimensions in PAS by selecting your model, then "Dimensions" and right-clicking on the affected dimension name and then the "View" option (or "List" or something related to displaying the dimension definition). You should see a PAS script that describes the dimension, including the dimension member IDs, descriptions and rollup levels. This should be consistent with your query results and hierarchies).
    Also, from the same menú you may also choose to "Delete" a dimension.
    Good luck!
    Regards

  • Can not use SUM in a simple query because of a syntax error?

    Hi
    Thank you for reading my post.
    I am trying to execute the following query:
    q = em.createQuery("SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))");
                  q.setParameter("contractor", contractor);
    q.setParameter("diameter", diameter);
         l =  (Long) q.getSingleResult();And I get the following error:
    Caused by: Exception [TOPLINK-8025] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.EJBQLException
    Exception Description: Syntax error parsing the query [SELECT SUM((NE.pipeLength - 0.6)+((NE.networkDepth-NE.initialDepth)*0.41)+ NE.standLenght)  FROM NExpansion NE  where (( NE.contract.contractor=:contractor) AND (NE.pDiameter=:diameter))], line 1, column 12: unexpected token [(].
    Internal Exception: line 1:12: unexpected token: (
            at oracle.toplink.essentials.exceptions.EJBQLException.unexpectedToken(EJBQLException.java:389)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.handleANTLRException(EJBQLParser.java:350)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.addError(EJBQLParser.java:278)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.reportError(EJBQLParser.java:378)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1416)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectExpression(EJBQLParser.java:1158)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectClause(EJBQLParser.java:403)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.selectStatement(EJBQLParser.java:178)
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.document(EJBQLParser.java:135)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.parse(EJBQLParser.java:166)
            at oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParser.buildParseTree(EJBQLParser.java:127)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:215)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:189)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:153)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:114)
            at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.<init>(EJBQueryImpl.java:99)
            at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
            at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:204)
            ... 30 more
    Caused by: line 1:12: unexpected token: (
            at oracle.toplink.essentials.internal.parsing.ejbql.antlr273.EJBQLParser.aggregateExpression(EJBQLParser.java:1365)
            ... 43 morePlease let me know what am I doing wrong?
    Thanks.

    Hello,
    From the grammar in the JPA spec, SUM only takes a state_field_path_expression which is defined as
    state_field_path_expression := {identification_variable | single_valued_association_path_expression}.state_field
    Please feel free to file an enhancement to have this expanded upon.
    Best Regards,
    Chris

  • Simple Query Question - How do I return the Last 3 records of a Table?

    Question.
    For example, I have a table that has 50 records.
    How do I, specify in SQL to only return the last 3 records of the table.
    Select a.* from table a where ????

    I was just trying to show an example to a friend on
    how something like this would work and if it was even possible. But it won't work. Here's a simple example:
    SQL> create table emp
      2  (id)
      3  as
      4  select object_id
      5  from   all_objects
      6  order  by object_id;
    Table created.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
         40830      55891
         40831      55892
         40832      55893So far, so good. These are the "last 3" rows inserted. Now delete a bunch of rows and insert 3 new ones:
    SQL> delete emp where id < 40000;
    33423 rows deleted.
    SQL> commit;
    Commit complete.
    SQL> insert into emp values (60000);
    1 row created.
    SQL> insert into emp values (60001);
    1 row created.
    SQL> insert into emp values (60002);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
          7410      55891
          7411      55892
          7412      55893Here's the problem. Even though the "last 3 rows" are 60000 - 60002, I still get the same ones as the first query.

Maybe you are looking for