SQL query error using Union

Hello!
I need some correction in the following query. I am trying to make a 2 page QPLD so I am joining 2 queries and then printing the report into 2 pages.
SELECT T0.[U_OANumber], T0.[custmrName], T0.[U_Inspection], T0.[U_Cust_PO_Num],
T0.[U_ModelType], T0.[U_Duty], T0.[U_NamePlate],
T0.[U_Indicator_Obs], T0.[U_Fastners], T0.[U_Mounting_Type], T0.[U_Casing_Orientation], T0.[U_Impeller_Dia],
T0.[U_Bearing_Style], T0.[U_Motor_HP_Size], T0.[U_InsulationWedges], T0.[U_Varnish], T0.[U_Paint_Shade],
T0.[U_PlugsSeal], T0.[U_Remarks], T0.[U_Despatch]
FROM OINS T0 WHERE T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
Union all
SELECT T0.[U_ModelType], T0.[U_Size], T0.[U_Discharge], T0.[U_Head], T0.[U_RPM], T0.[U_YOM], T0.[U_HP],
T0.[U_Amps], T0.[U_Insulation_Class], T0.[U_Winding_Connection]
FROM OINS T0 WHERE
T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
Do I have to use the where clause just once since it is identical to both statements?
I get the error stating that all queries using Union, Intersect or Except must have an equal number of expressions. what does this mean?
scorp
Edited by: scorpion 666 on Feb 12, 2009 1:30 PM

Union has to have exact same numbers of fields to combine two results.  Your query shows no need of union because your where clauses are identical.
Right syntax would be like this:
SELECT T0.[U_OANumber], T0.[custmrName], T0.[U_Inspection], T0.[U_Cust_PO_Num],
T0.[U_ModelType], T0.[U_Duty], T0.[U_NamePlate],
T0.[U_Indicator_Obs], T0.[U_Fastners], T0.[U_Mounting_Type], T0.[U_Casing_Orientation], T0.[U_Impeller_Dia],
T0.[U_Bearing_Style], T0.[U_Motor_HP_Size], T0.[U_InsulationWedges], T0.[U_Varnish], T0.[U_Paint_Shade],
T0.[U_PlugsSeal], T0.[U_Remarks], T0.[U_Despatch], T0.[U_Size], T0.[U_Discharge], T0.[U_Head], T0.[U_RPM], T0.[U_YOM], T0.[U_HP],
T0.[U_Amps], T0.[U_Insulation_Class], T0.[U_Winding_Connection]
FROM DBO.OINS T0 WHERE T0.[U_OANumber] = '[%0]' or  T0.[customer] = '[%1]' or T0.[manufSN] = '[%2]'
Thanks,
Gordon

Similar Messages

  • Sql query to get union of matching rows

    I want to write a sql query that shows union f all the [Type] for each [Key] if [Key] has atleast one [Type] in common and for non matched [Key]s it will return the row as it is.
    For example In the sql table below [Key] '1' and '2' has [Type] 'B' in common and [Key] '1' and '4' has [Type] 'A' in common. In this case [Key] '1', '2' and '4' are related so result will be union of [Type]s in [Key]s '1', '2' and '4' which are 'A', 'B', 'C'
    and 'E' for each [Key]. And [Key] '3' has no [Type] in common so it will return itself.
    Input:
    declare @categories table ([Key] int, [Type] Char(1))
    insert into @categories ([Key], [Type]) values (1, 'A')
    insert into @categories ([Key], [Type]) values (1, 'B')
    insert into @categories ([Key], [Type]) values (2, 'B')
    insert into @categories ([Key], [Type]) values (2, 'C')
    insert into @categories ([Key], [Type]) values (3, 'D')
    insert into @categories ([Key], [Type]) values (4, 'E')
    insert into @categories ([Key], [Type]) values (4, 'A')
    insert into @categories ([Key], [Type]) values (5, 'F')
    insert into @categories ([Key], [Type]) values (5, 'G')
    insert into @categories ([Key], [Type]) values (6, 'G')
    insert into @categories ([Key], [Type]) values (6, 'H')
    Desired output:
    Key Type
    1 A
    1 B
    1 C
    1 E
    2 A
    2 B
    2 C
    3 D
    4 A
    4 B
    4 E
    5 F
    5 G
    5 H
    6 F
    6 G
    6 H

      
    The data element names are wrong. KEY is a reserved word; “Categories" and "type" are called attribute properties in ISO-11179 rules. Matthias Kläy is right; this is a graph problem in disguise, but you can do it with set theory to get  what are called
    equivalence classes. 
    An edge in a graph has two nodes. Some authors allow a single node to count as a edge, but a better way is to put the same node on both ends of the edge. Here is the graph in a table with all the needed constraints. This is why you should post DDL and not be
    so rude.  
    DROP TABLE Graph;
    CREATE TABLE Graph
    (edge INTEGER NOT NULL,
     node_1 CHAR(1) NOT NULL,
     node_2 CHAR(1) NOT NULL,
     CHECK (node_1 <= node_2),
     PRIMARY KEY (node_1, node_2));
    Here is your data in the correct format. 
    INSERT INTO Graph 
    VALUES 
     (1, 'A', 'B'),
     (2, 'B', 'C'),
     (3, 'D', 'D'), -- orphan node
     (4, 'A', 'E'),
     (5, 'F', 'G'),
     (6, 'G', 'H');
    Now Google Warshall's Algorithm. It uses three nested loops and an adjacency array. This is very clean and fast in a procedural language. Not so much in SQL. Let us do this in steps:
    WITH X1 (edge, node1_1, node1_2, node2_1, node2_2 )
    AS
    (SELECT CASE WHEN G1.edge <> G2.edge 
           THEN G1.edge ELSE G2.edge END,
           G1.node_1, G1.node_2, 
           G2.node_1, G2.node_2       
      FROM Graph AS G1, Graph AS G2
     WHERE G1.node_1 IN (G2.node_1, G2.node_2) 
       AND G1.edge <> G2.edge),
    X2 (edge, node_1, node_2)
    AS
    (SELECT edge, 
    CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
    CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
    FROM X1)
    SELECT DISTINCT edge,
           CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
           CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
     FROM X2;
    The X1 subquery gets the paths of length two. The X2 subquery removes the middle node and creates a new sorted edge. Insert these new rows into Graphs, if they are not there. Repeat the process until no more rows are added. 
    DROP TABLE Graph;
    CREATE TABLE Graph
    (edge INTEGER NOT NULL,
     node_1 CHAR(1) NOT NULL,
     node_2 CHAR(1) NOT NULL,
     CHECK (node_1 <= node_2),
     PRIMARY KEY (node_1, node_2));
    INSERT INTO Graph 
    VALUES 
     (1, 'A', 'B'),
     (2, 'B', 'C'),
     (3, 'D', 'D'), -- orphan node
     (4, 'A', 'E'),
     (5, 'F', 'G'),
     (6, 'G', 'H');
    Here is the monster rolled up into a single statement. 
    INSERT INTO Graph
    SELECT DISTINCT edge,
           CASE WHEN node_1 < node_2 THEN node_1 ELSE node_2 END,
           CASE WHEN node_2 < node_1 THEN node_1 ELSE node_2 END
     FROM (SELECT edge, 
    CASE WHEN node1_1 IN (node2_1, node2_2) THEN node1_2 ELSE node1_1 END,
    CASE WHEN node2_1 IN (node1_1, node1_2) THEN node2_2 ELSE node2_1 END
    FROM 
    (SELECT CASE WHEN G1.edge < G2.edge 
           THEN G1.edge ELSE G2.edge END,
           G1.node_1, G1.node_2, 
           G2.node_1, G2.node_2       
      FROM Graph AS G1, Graph AS G2
     WHERE G1.node_1 IN (G2.node_1, G2.node_2) 
       AND G1.edge <> G2.edge) AS X1(edge,node1_1, node1_2, node2_1, node2_2) )
        AS X2(edge, node_1, node_2)
    EXCEPT 
     SELECT * FROM Graph;
     SELECT * FROM Graph ORDER BY edge, node_1, node_2;
    1 A B
    1 A C
    1 B E
    1 C E
    2 B C
    3 D D
    4 A E
    5 F G
    5 F H
    6 G H
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • HOW TO FIND AND CORRECT THE SQL QUERY ERRORS ????

    Sometimes I get the errors while executing the sql queries.
    I just wanted to know about the various ways by which I can find the sql query errors .
    Any suggestions will be deeply appreciated.

    If you get the an error from SSMS and you can't comprehend it, you can google the error message and google would always lead you to the correction. Or you can post the error in this forum, people
    here are always kind and ready to help :).
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • 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

  • SQL Query (PL/SQL function body returning SQL query) Error

    I'm an ApEx newbie, not a PL/SQL developer (more of a Web application developer) and I'm getting an error that prevents me from saving some PL/SQL code. I've looked over it all afternoon, but can't tell what's wrong. I may even be trying to do something inappropriately, or really stupid.
    The code is below. The error I get is - "Function returning SQL query: Query cannot be parsed within the Builder". Any help is appreciated, and thanks in advance. If you need more details of what I'm trying to do let me know.
    = = = = = = =
    DECLARE
    v_ID NUMBER;
    v_SITE_ID NUMBER;
    v_SITE_CODE VARCHAR2(15);
    v_ADDR1 VARCHAR2(240);
    v_CITY VARCHAR2(25);
    v_STATE VARCHAR2(150);
    v_ZIP VARCHAR2(20);
    v_ORG_ID VARCHAR2(10);
    BEGIN
    IF :G_ORG_ID = '' THEN
    SELECT "VENDOR_ID", "VENDOR_SITE_ID", "VENDOR_SITE_CODE", "ADDRESS_LINE1", "CITY", "STATE", "ZIP", "ORG_ID"
    INTO v_ID, v_SITE_ID, v_SITE_CODE, v_ADDR1, v_CITY, v_STATE, v_ZIP, v_ORG_ID
    FROM "PO_VENDOR_SITES_ALL_V"
    WHERE ("VENDOR_ID" = :P4_VENDOR_ID);
    ELSE
    SELECT "VENDOR_ID", "VENDOR_SITE_ID", "VENDOR_SITE_CODE", "ADDRESS_LINE1", "CITY", "STATE", "ZIP", "ORG_ID"
    INTO v_ID, v_SITE_ID, v_SITE_CODE, v_ADDR1, v_CITY, v_STATE, v_ZIP, v_ORG_ID
    FROM "PO_VENDOR_SITES_ALL_V"
    WHERE (("VENDOR_ID" = :P4_VENDOR_ID) AND ("ORG_ID" = :G_ORG_ID));
    END IF;
    END;

    Denes,
    Good question.
    Before I answer that question I'll give some detail on the application. That may help too. The application is a supplier search which searches the Oracle vendor tables (po.vendors, po_vendor_sites_all, po_vendor_contacts). The vendor/vendor site relationship is one to many. The site is based on the Org_ID. The supplier search is built to work solo, or to be called by another application. If it is called by another application one of the values passed is the Org_ID, so that only the sites that pertain to the user's org_id are shown. If the appl is called solo the Org_ID is not known, so the SQL should return all sites.
    I figured the easiest way to check if the program was running solo or was called was to check the G_ORG_ID value in my PL/SQL that builds the site report. You helped me with that code. (I am hiding buttons by checking if the G_ORG_ID field is null and they display/hide properly.)
    So, how is G_ORG_ID populated? It is on Page Zero, and is populated via the URL when the appl is called. (That aspect works great.) If it is called by another application G_ORG_ID is populated and my PL/SQL works. But, if the appl is called solo the field is not populated. When the PL/SQL runs I cannot get it to run the code for when G_ORG_ID is not populated.
    I am at the point that I don't know if I need to populate G_ORG_ID in some way when the appl is running solo (kinda tricky, because I need to use that field to determine if it is running solo), or if I need to check it differently in the PL/SQL IF.
    I have experimented with both the default value, and have checked for different values in the PL/SQL IF, but nothing works.
    Thanks for your help, and let me know if you have any other questions on this matter.
    Thanks, Tony

  • SQL query error

    I have a complicated SQL query which looks like the following:
    UPDATE SeqPick
    SET SeqPick.AceTopAge = SEQS.TopAge, SeqPick.AceBaseAge = SEQS.BaseAge
    FROM T_Well_SeqPick SeqPick INNER JOIN (SELECT TOPS.Sequence_Name, TOPS.Sequence_ID, TOPS.TopAge, BASES.BaseAge FROM (SELECT dd.Sequence_Name, dd.Sequence_ID, Age_Top+(Age_Base-Age_Top)*Top_Ratio As TopAge FROM T_Sequences dd, T_Stages WHERE(dd.SeqScheme_ID
    = 3) And T_Stages.Stage_Name_ID=Top_Stage_ID And T_Stages.Timescale_ID=1) TOPS INNER JOIN (SELECT BaseSeq.Sequence_Name, BaseSeq.Sequence_ID, Age_Top+(T_Stages.Age_Base-T_Stages.Age_Top)*Base_Ratio As BaseAge FROM T_Sequences BaseSeq, T_Stages Where SeqScheme_ID=3
    AND Stage_Name_ID=Base_Stage_ID AND Timescale_ID=1) BASES ON TOPS.Sequence_ID=BASES.Sequence_ID ORDER BY TopAge, BaseAge) SEQS ON SeqPick.Seq_ID = SEQS.Sequence_ID
    When I run it on a SQL Server 2008, I get the following error message:
    SQL Server Exception Error:
    System.Data.SqlClient.SqlException: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
    Are there any other ways of re-writing the above query to resolve the issue?

    As Erland said, query should be readable. You can easily format it by using
    http://poorsql.com/
    It formats your query like below:
    UPDATE SeqPick
    SET SeqPick.AceTopAge = SEQS.TopAge
    , SeqPick.AceBaseAge = SEQS.BaseAge
    FROM T_Well_SeqPick SeqPick
    INNER JOIN (
    SELECT TOPS.Sequence_Name
    , TOPS.Sequence_ID
    , TOPS.TopAge
    , BASES.BaseAge
    FROM (
    SELECT dd.Sequence_Name
    , dd.Sequence_ID
    , Age_Top + (Age_Base - Age_Top) * Top_Ratio AS TopAge
    FROM T_Sequences dd
    , T_Stages
    WHERE (dd.SeqScheme_ID = 3)
    AND T_Stages.Stage_Name_ID = Top_Stage_ID
    AND T_Stages.Timescale_ID = 1
    ) TOPS
    INNER JOIN (
    SELECT BaseSeq.Sequence_Name
    , BaseSeq.Sequence_ID
    , Age_Top + (T_Stages.Age_Base - T_Stages.Age_Top) * Base_Ratio AS BaseAge
    FROM T_Sequences BaseSeq
    , T_Stages
    WHERE SeqScheme_ID = 3
    AND Stage_Name_ID = Base_Stage_ID
    AND Timescale_ID = 1
    ) BASES ON TOPS.Sequence_ID = BASES.Sequence_ID
    --ORDER BY TopAge
    -- , BaseAge
    ) SEQS ON SeqPick.Seq_ID = SEQS.Sequence_ID
    -Vaibhav Chaudhari

  • JSTL, MySQL, Tomcat sql:query error

    Hi to everyone...
    This is my first post, but since im employed now as a java developer ill be here regulary.
    Right now im trying to use the JSTL to make some simple sql selects in my JSPs....
    Here�s the JSP code:
    <%@ page language="java" import="java.lang.*,java.util.*" %>
    <%@ taglib uri="/jstl-core" prefix="c" %>
    <%@ taglib uri="/jstl-sql" prefix="sql" %>
    <html>
    <head>
    <title> A first JSP database </title>
    </head>
    <body>
    <sql:setDataSource scope="session" var="dataSource"
    url="jdbc:mysql://127.0.0.1/zolltek" driver="com.mysql.jdbc.Driver"
    user="root" password="root"/>
    <!-- The following UPDATE works fine.. -->
    <sql:update var="users" dataSource="${dataSource}" scope="session">
    INSERT INTO test VALUES (7,'Paul Oakenfold')
    </sql:update>
    <!-- But the select screws up.... -->
    <sql:query var="users" dataSource="${dataSource}" scope="session">
    SELECT * FROM test WHERE 1
    </sql:query>
    </body>
    </html>
    ...and the error message:
    exception :
    org.apache.jasper.JasperException:
    SELECT * FROM test WHERE 1
    : null
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    root cause
    javax.servlet.ServletException:
    SELECT * FROM test WHERE 1
    : null
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:531)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:84)
    ...and just for completion the importent part of my web.xml:
    <taglib>
    <taglib-uri>/jstl-core</taglib-uri>
    <taglib-location>/WEB-INF/c-1_0.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>/jstl-sql</taglib-uri>
    <taglib-location>/WEB-INF/sql-1_0.tld</taglib-location>
    </taglib>
    i am using the jboss 3.2.3 tomcat bundle (tomcat 4.1.29)
    and mysql 4.0.18 on W32 System....
    the JSTL is installed and working - i can make <sql:update>Inserts without any problems, but any <sql:query>selects result in that error... so i guess the setDataSource is okay...
    Any idea would be appreciated....
    Thx
    J�rg

    Those URIs you've got in your JSPs aren't correct. They should be:
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    These are the URIs defined in the standard.jar.
    You'd be better off setting up a Tomcat JNDI data source for your application. That will externalize the connection parameters and make it unnecessary to refer to a data source in your JSPs.
    You'd be even better off not putting SQL code in your JSPs. They're for presentation. Better to write a Java object that will communicate with the database on the JSP's behalf.
    If you just want to select all the rows in the table, the query should be "SELECT * FROM test". You don't need a WHERE clause in that case.
    If you change the URIs in your JSPs you should remove the <taglib> from your web.xml. It's not necessary. Tomcat will find the TLD by looking in the JARs in the CLASSPATH and matching the URIs.

  • Validate and Edit SQL Query Errors

    I am trying to "Validate or Edit SQL Query" in APEX 3.0. When I open up the SQL Query its highlighted in red and when I click on the Validate or Edit button it gives me an error.
    I modified my marvel.conf file to include:
    AddType text/xml xbl
    AddType text/x-component htc
    and this still didnt take care of it. Any ideas and thank you in advance.
    PS: OPS - Windows Server 2003
    Upgraded from 1.6 to 3.0

    I've gotten so used to command line editing, that I rarely us "ed". back in the days of DOS, the default editor was EDLIN - one of those goofy editors that only showed one line at a time, so it wasn't much of an improvement. you could switch to the old dos editor, but that wasn't much better (just checked, it's still there)
    some nice things with command line editing
    to change everthing between the first two single quotes
    c/'...'/'new criteria'to remove everything after a specific string
    c/from.../fromto change a string that contains (or will contain) slashes
    c.1/2.1/4.

  • Native SQL Query Error: DBIF_DSQL2_SQL_ERROR -- ORA-00936: missing express

    Hi,
    I tried to read data using the following SQL Query,
    fp_work = 'ABCD'.
      EXEC SQL PERFORMING WRITE_TO_ITAB .
      SELECT fp_code, bank_acc_code, bank_acc_num,
      INTO :gs_cds_data-FP_CODE,
               :gs_cds_data-BANK_ACC_CODE,
               :gs_cds_data-BANK_ACC_NUM,
       FROM  BANK_TABLE
      WHERE fp_code = :fp_wrk
      ENDEXEC.
    *&      Form  WRITE_to_itab
    FORM write_to_itab.
    To move the data into the Internal Table.
      APPEND gs_cds_data TO gt_cds_data.
      CLEAR  gs_cds_data.
    ENDFORM.                    "WRITE_to_itab
    and im getting the run time error..
    What happened?                                                                               
    The error occurred in the current database connection "SAPABC".                                                                               
    How to correct the error                                                                               
    Database error text........: "ORA-00936: missing expression"             
    Triggering SQL statement...: "FETCH NEXT "                               
    Internal call code.........: "[DBDS/NEW DSQL]"                           
    Please check the entries in the system log (Transaction SM21).                                                                               
    You may able to find an interim solution to the problem                  
    in the SAP note system. If you have access to the note system yourself,  
    use the following search criteria:                                                                               
    "DBIF_DSQL2_SQL_ERROR" C                                                                               
    If you cannot solve the problem yourself, please send the                
    following documents to SAP:
    Can anyone give me a solution to correct this error?
    In addition, Can i omit the WHERE clause, as i need to get all the data in the oracle database?

    BUT,
          EXEC SQL.
            connect to :LV_DB_NAME as :sy-uname
          ENDEXEC.
          EXEC SQL.
            SET CONNECTION :sy-uname
          ENDEXEC.
         check sy-subrc..
    connection is happening.. with sy-subrc value as ZERO

  • How to set fetchsize of sql Query when using Database Adapter.

    Hi All,
    I am using DatabaseAdapter to connect to database and retriving huge amount of data.For improvement in the performance I want to set the "fetchsize" of sql query. I know fetchsize can be preset in Java using Jdbc 2.0 API.Please let me know how to set this value in BPEL when using DBAdapter?
    Thanks
    Chandra

    I talked to the developer of the db adapter - and he told me this feature will be available in BPEL PM 10.1.3 (which is supposed to be production later this year, and a public beta soon). If this is an emergency I would recommend going throug Oracle support and have them file an enhancement for 10.1.2.0.2
    hth clemens

  • SQL Query (PL/SQL function body returning SQL query) when using to_char

    we are trying to build a report page of Type SQL Query (PL/SQL function body returning SQL query).
    our query is so simple, we need to extract the month from the recording_date column.
    declare
    l_query varchar2(1000);
    begin
    l_query:='select to_char(recording_date,'MM')from re_productive';
    return l_query;
    end;
    but we are having the following problem for this query
    Function returning SQL query: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the generic columns checkbox below the region source to proceed without parsing.
    (ORA-06550: line 4, column 42: PLS-00103: Encountered the symbol "MON" when expecting one of the following: . ( * @ % & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like between || multiset member SUBMULTISET_ The symbol ". was inserted before "MON" to continue.)
    Notes:
    1-the query is correct and it was tested under Toad and SQL Plus.
    2- we tried Use Generic Column Names (parse query at runtime only) option but we get the same problem.
    any quick help please.

    Hi
    You haven't escaped your quotes in the string. Try this...
    DECLARE
    l_query VARCHAR2(32767);
    BEGIN
    l_query:= 'select to_char(recording_date,''MM'') from re_productive';
    RETURN l_query;
    END;Cheers
    Ben

  • SQL Query C# Using Execution Plan Cache Without SP

    I have a situation where i am executing an SQL query thru c# code. I cannot use a stored procedure because the database is hosted by another company and i'm not allowed to create any new procedures. If i run my query on the sql mgmt studio the first time
    is approx 3 secs then every query after that is instant. My query is looking for date ranges and accounts. So if i loop thru accounts each one takes approx 3 secs in my code. If i close the program and run it again the accounts that originally took 3 secs
    now are instant in my code. So my conclusion was that it is using an execution plan that is cached. I cannot find how to make the execution plan run on non-stored procedure code. I have created a sqlcommand object with my queary and 3 params. I loop thru each
    one keeping the same command object and only changing the 3 params. It seems that each version with the different params are getting cached in the execution plans so they are now fast for that particular query. My question is how can i get sql to not do this
    by either loading the execution plan or by making sql think that my query is the same execution plan as the previous? I have found multiple questions on this that pertain to stored procedures but nothing i can find with direct text query code.
    Bob;
     

    I did the query running different accounts and different dates with instant results AFTER the very first query that took the expected 3 secs. I changed all 3 fields that i've got code for parameters for and it still remains instant in the mgmt studio but
    still remains slow in my code. I'm providing a sample of the base query i'm using.
    select i.Field1, i.Field2, 
    d.Field3  'Field3',
    ip.Field4 'Field4', 
    k.Field5 'Field5'
    from SampleDataTable1 i, 
    SampleDataTable2 k, 
    SampleDataTable3 ip,
    SampleDataTable4 d 
    where i.Field1 = k.Field1 and i.Field4 = ip.Field4 
    i.FieldDate between '<fromdate>' and  '<thrudate>' 
    and k.Field6 = <Account>
    Obviously the field names have been altered because the database is not mine but other then the actual names it is accurate. It works it just takes too long in code as described in the initial post. 
    My params setup during the init for the connection and the command.
    sqlCmd.Parameters.Add("@FromDate", SqlDbType.DateTime);
            sqlCmd.Parameters.Add("@ThruDate", SqlDbType.DateTime);
            sqlCmd.Parameters.Add("@Account", SqlDbType.Decimal);
    Each loop thru the code changes these 3 fields.
        sqlCommand.Parameters["@FromDate"].Value = dtFrom;
        sqlCommand.Parameters["@ThruDate"].Value = dtThru;
        sqlCommand.Parameters["@Account"].Value = sAccountNumber;
    SqlDataReader reader = sqlCommand.ExecuteReader();
            while (reader.Read())
                reader.Close();
    One thing i have noticed is that the account field is decimal(20,0) and by default the init i'm using defaults to decimal(10) so i'm going to change the init to 
       sqlCmd.Parameters["@Account"].Precision = 20;
       sqlCmd.Parameters["@Account"].Scale = 0;
    I don't believe this would change anything but at this point i'm ready to try anything to get the query running faster. 
    Bob;

  • SQL Loader Error using regexp_replace

    Hi Guys,
    i am trying to using sql loader to load data and one column in control file is
    x1 POSITION(718:725) DATE "YYYYMMDD" NULLIF FI_CLM_RCPT_DT = BLANKS,
    XYZ POSITION(736:745) CHAR "regexp_replace(substr(:XYZ,1,9),\'[^1|Y|N|U|W]\',\' \')||regexp_replace(substr(:XYZ,10,1),\'[^Z]\', \' \'))")
    But at last part i am getting error
    SQL*Loader-951: Error calling once/load initialization
    ORA-02373: Error parsing insert statement for table TDESAI_DBA.HAJI_CLM_A.
    ORA-00933: SQL command not properly ended
    I know the error is with XYZ Column but where. Or am i doing something wrong?
    Can you guys help me

    Please see the discussion on the Semantic Technologies OTN form at SQL*Loader error 350 using SDO_RDF_TRIPLE_S constructor

  • Java Web Analyzer security hole in SQL Query Spreadsheet using JDBC-ODBC bridge

    Hi,<BR><BR>I use Hyperion Analyzer 7.0.1 on Windows 2003 and relation database DB2 v8.2.<BR><BR>I did:<BR>1. log in to Java Web Analyzer<BR>2. button New<BR>3. Select Layout: Custom Report<BR>4. from toolbar pull down to desktop "SQL Spreadsheet" option<BR>5. "Enter SQL Query" window opens, from JDBC Driver drop down window select "JDBC-ODBC Bridge"<BR>6. in "JDBC Connection String" window replace "db1" string with database name<BR>7. leave JDBC Username and JDBC Password empty (this is default)<BR>8. click on "Test Connection" button.<BR>9. "Test Connection" window opens with message "Connection Succeded"!!! So connection to database without password succeeded.<BR>10. in "SQL Query window" write any SQL you wish and Database will execute the SQL.<BR><BR><b>Conclusion: Connecting Analyzer with SQL Spreadsheet option to relation database DB2 is possible without password.</b><BR><BR>Question: Is there any way to prevent users from executing "SQL Spreedsheet" option?<BR><BR>Thanks,<BR>Grofaty

    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection(dsn,"guest","guest");
    OR DriverManager.getConnection(dsn);
    System.out.println("Conection's opened");
    catch(ClassNotFoundException cnfe)
    System.err.println(cnfe);
    catch(SQLException sqle)
    System.err.println(sqle);
    try that code and double check you DSN Name . it's a good practice to greate a system DSN.
    i hope that helps.
    FEEL FREE TO ASK. WON'T BITE U
    ABDUL

Maybe you are looking for

  • Reversing placement of XML without using Undo

    I lay out XML by importing it into the structure pane and then dragging and dropping elements onto frames in my layout. If I drop an element in the wrong frame I can undo this using Undo. However, if I have done some work on the layout since the inco

  • Picture of myself appears in every email I send!

    A few days ago a thumbnaail size picture of myself started appearing in the upper right hand corner of every email I send. I have no idea as to what I did to make this start happening or how to make it stop.

  • Delete conference does not return a client session id

    1. We have a CISCO TMS 14.6 and use TMS Booking API v15. When making a saveConference if the session id is blank, a session id is created and returned in the SOAP fault. But that is not the case with delete conference. If there is no client session i

  • RFC using global class.

    Hello Folks, I have developed FM using global class(se24), just calling method inside FM. My question is that, which has more prefrence a class or PERFORM. Thanks, Amol.

  • Can we all Rally and ALL request the Cellular settings to include 3G on/off on the iPad?

    it SEEMS when you're in a terrible area or have a carrier that is on drugs, and can't seem to keep things working, the iPad is missing the feature to turn OFF 3g Cell modem coverage  - without this simple feature, the iPad can't connect to anything a