Help with SQL to Pivot SQL

I have requirment to build the SQL to Merge rows value to a single value.
Here is the Data
TABLE_A
ID SEQ MESG
1 1 MSG1
1 2 MSG2
2 1 MSG1
3 1 MSG1
3 2 MSG2
3 3 MSG3
I need output as
ID MSG
1 MSG1 MSG2
2 MSG1
3 MSG1 MSG2 MSG3

Create function like below:
CREATE OR REPLACE  FUNCTION rowtocol( p_slct IN VARCHAR2, p_dlmtr IN VARCHAR2 DEFAULT ',' ) RETURN VARCHAR2
AUTHID CURRENT_USER AS
    TYPE c_refcur IS REF CURSOR;
    lc_str VARCHAR2(4000);
    lc_colval VARCHAR2(4000);
    c_dummy c_refcur;
    l number;
BEGIN
    OPEN c_dummy FOR p_slct;
    LOOP
    FETCH c_dummy INTO lc_colval;
    EXIT WHEN c_dummy%NOTFOUND;
    lc_str := lc_str || p_dlmtr || lc_colval;
    END LOOP;
    CLOSE c_dummy;
    RETURN SUBSTR(lc_str,2);
       EXCEPTION
       WHEN OTHERS THEN
          lc_str := SQLERRM;
          IF c_dummy%ISOPEN THEN
          CLOSE c_dummy;
          END IF;
       RETURN lc_str;
END;
/And print result like :
   SELECT DISTINCT  a.job,
      rowtocol(  'SELECT ename  FROM emp
                       WHERE
                       job = ' || '''' || a.job || '''' || ' ORDER BY ename'
     AS Employees
    FROM emp;

Similar Messages

  • Help with oracle 11g pivot operator

    i need some help with oracle 11g pivot operator. is it possible to use multiple columns in the FOR clause and then compare it against multiple set of values.
    here is the sql to create some sample data
    create table pivot_data ( country_code number , dept number, job varchar2(20), sal number );
    insert into pivot_data values (1,30 , 'SALESMAN', 5000);
    insert into pivot_data values (1,301, 'SALESMAN', 5500);
    insert into pivot_data values (1,30 , 'MANAGER', 10000);     
    insert into pivot_data values (1,301, 'MANAGER', 10500);
    insert into pivot_data values (1,30 , 'CLERK', 4000);
    insert into pivot_data values (1,302, 'CLERK',4500);
    insert into pivot_data values (2,30 , 'SALESMAN', 6000);
    insert into pivot_data values (2,301, 'SALESMAN', 6500);
    insert into pivot_data values (2,30 , 'MANAGER', 11000);     
    insert into pivot_data values (2,301, 'MANAGER', 11500);
    insert into pivot_data values (2,30 , 'CLERK', 3000);
    insert into pivot_data values (2,302, 'CLERK',3500);
    using case when I can write something like this and get the output i want
    select country_code
    ,avg(case when (( dept = 30 and job = 'SALESMAN' ) or ( dept = 301 and job = 'SALESMAN' ) ) then sal end ) as d30_sls
    ,avg(case when (( dept = 30 and job = 'MANAGER' ) or ( dept = 301 and job = 'MANAGER' ) ) then sal end ) as d30_mgr
    ,avg(case when (( dept = 30 and job = 'CLERK' ) or ( dept = 302 and job = 'CLERK' ) ) then sal end ) as d30_clrk
    from pivot_data group by country_code;
    output
    country_code          D30_SLS               D30_MGR               D30_CLRK
    1      5250      10250      4250
    2      6250      11250      3250
    what I tried with pivot is like this I get what I want if I have only one ( dept,job) for one alias name. I want to call (30 , 'SALESMAN') or (301 , 'SALESMAN') AS d30_sls. any help how can I do this
    SELECT *
    FROM pivot_data
    PIVOT (SUM(sal) AS sum
    FOR (dept,job) IN ( (30 , 'SALESMAN') AS d30_sls,
              (30 , 'MANAGER') AS d30_mgr,               
    (30 , 'CLERK') AS d30_clk
    this is a simple example .... my real life scenario is compliated with more fields and more combinations .... So something like using substr(dept,1,2) won't work in my real case .
    any suggestions get the result similar to what i get in the case when example is really appreciated.

    Hi,
    Sorry, I don't think there's any way to get exactly what you requested. The values you give in the PIVOT ... IN clause are exact values, not alternatives.
    You could do something like this to map all alternatives to a common value:
    WITH     got_dept_grp     AS
         SELECT     country_code, job, sal
         ,     CASE
                  WHEN  job IN ('SALESMAN', 'MANAGER') AND dept = 301 THEN 30
                  WHEN  job IN ('CLERK')               AND dept = 302 THEN 30
                                                                     ELSE dept
              END     AS dept_grp
         FROM     pivot_data
    SELECT     *
    FROM     got_dept_grp
    PIVOT     (     AVG (sal)
         FOR     (job, dept_grp)
         IN     ( ('SALESMAN', 30)
              , ('MANAGER' , 30)
              , ('CLERK'   , 30)
    ;In your sample data (and perhaps in your real data), it's about as easy to explicitly define the pivoted groups individually, like this:
    WITH     got_pivot_key     AS
         SELECT     country_code, sal
         ,     CASE
                  WHEN  job = 'SALESMAN' AND dept IN (30, 301) THEN 'd30_sls'
                  WHEN  job = 'MANAGER'  AND dept IN (30, 301) THEN 'd30_mgr'
                  WHEN  job = 'CLERK'    AND dept IN (30, 302) THEN 'd30_clrk'
              END     AS pivot_key
         FROM    pivot_data
    SELECT     *
    FROM     got_pivot_key
    PIVOT     (     AVG (sal)
         FOR     pivot_key
         IN     ( 'd30_sls'
              , 'd30_mgr'
              , 'd30_clrk'
    ;Thanks for posting the CREATE TABLE and INSERT statements; that really helps!

  • Help with "ORA-06511: PL/SQL: cursor already open"

    I've tried numerous variations on this piece of code and I always get the same result. I'm sure this is painfully obvious to an experienced PL/SQL person.
    Any help will be appreciated!
    Thank You!
    1 DECLARE
    2 CURSOR EMP_CURSOR IS SELECT last_name from employees;
    3 current_last_name varchar2(25);
    4 BEGIN
    5 IF EMP_CURSOR%ISOPEN
    6 THEN
    7 dbms_output.put_line ('cursor is already open');
    8 close EMP_CURSOR;
    9 END IF;
    10 dbms_output.put_line ('opening cursor');
    11 OPEN EMP_CURSOR;
    12 FOR item in EMP_CURSOR LOOP
    13 FETCH EMP_CURSOR INTO current_last_name;
    14 EXIT WHEN EMP_CURSOR%NOTFOUND;
    15 dbms_output.put_line (item.last_name);
    16 END LOOP;
    17 CLOSE EMP_CURSOR;
    18* END;
    19 /
    DECLARE
    ERROR at line 1:
    ORA-06511: PL/SQL: cursor already open
    ORA-06512: at line 2
    ORA-06512: at line 12

    Mathieu,
    Log in as anotherSchema and grant select on 'IDsTable' to the current user.
    SQL> r
      1  create or replace function f1(theID varchar2) return mytype pipelined is
      2  out varchar2(30);
      3  cursor myCursor (x varchar2) is select * from scott.emp where job=x;
      4  begin
      5  for rec in myCursor(theID) loop
      6  pipe row(rec.ename);
      7  end loop;
      8  return;
      9* end;
    Warning: Function created with compilation errors.
    SQL> show errors
    Errors for FUNCTION F1:
    LINE/COL ERROR
    3/33     PL/SQL: SQL Statement ignored
    3/53     PL/SQL: ORA-00942: table or view does not exist
    6/1      PL/SQL: Statement ignored
    6/10     PLS-00364: loop index variable 'REC' use is invalid
    SQL> connect scott
    Enter password: *****
    Connected.
    SQL> grant select on emp to testuser;
    Grant succeeded.
    SQL> connect testuser
    Enter password: ****
    Connected.
    SQL> create or replace function f1(theID varchar2) return mytype pipelined is
      2  out varchar2(30);
      3  cursor myCursor (x varchar2) is select * from scott.emp where job=x;
      4  begin
      5  for rec in myCursor(theID) loop
      6  pipe row(rec.ename);
      7  end loop;
      8  return;
      9  end;
    10  /
    Function created.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.3.0 - Production
    SQL>

  • Help with search within pl/sql code

    Hi All,
    Can you please help me to find all the objects with a database link.
    I have some procedures,function and packages which uses database link. I need to fetch all the objects that uses a database link. Is there any way to get the list of object names using any database link?
    Thanks in advance
    Apppreciate your help!
    Thanks
    Bob

    hi there,
    the problem with dba_source is that the code might be wrapped.
    another possibility is to query dba_dependencies, column referenced_link
    Also you can have pl/sql routines that create dynamically code and might use dblinks in their dynamic code.
    So you might not be able to be 100 percent complete.
    HTH Mathias

  • Help with escape option in sql

    SQL> select sname from shares where sname like 'VIS_%';
    SNAME
    VISAKAIND
    VISASTEEL
    VISESHINFO
    VISHALEXPO
    VISHALRET
    VISUINTL
    VIS_SIN
    7 rows selected.
    SQL> select sname from shares where sname like 'VIS\_%';
    SNAME
    VISAKAIND
    VISASTEEL
    VISESHINFO
    VISHALEXPO
    VISHALRET
    VISUINTL
    VIS_SIN
    7 rows selected.
    SQL> select sname from shares where sname like 'VIS_\%';
    SNAME
    VISAKAIND
    VISASTEEL
    VISESHINFO
    VISHALEXPO
    VISHALRET
    VISUINTL
    VIS_SIN
    7 rows selected.
    could u people please help me to get the row with the sname vis_sin only....

    Hi Sybrand - here it is - please point to the error
    if you see it...
    Thanks.
    Connected to:
    Oracle Database 10g Enterprise Edition Release
    10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select table_name from dba_tables where
    table_name like 'PS\_%' and rownum<10 escape '\';
    select table_name from dba_tables where table_name
    like 'PS\_%' and rownum<10 escape '\'
    ERROR at line 1:
    ORA-00933: SQL command not properly endedselect table_name from dba_tables where table_name like 'PS\_%' escape '\' and rownum < 10;
    the 'escape' is part of the like condition so you need it contiguous to the like clause.

  • I need help with network install of SQL Developer 3.2

    All,
    Does anyone have any references on how to perform a network install for SQL Developer? Here is what I'm trying to achieve:
    1. Network installation on drive S:\ (Windows, obviously)
    2. User links to network installation
    3. Connections are unique for each user
    I found the 2006 posting of network install for Raptor, but I could not find anything that correlates with the latest release. All I have done so far is downloaded and unzipped. Any help/instructions/guides/tutorials are welcome.

    You have installed!.  The code for SQLDeveloper does not have an installer.
    If the software is on S, say a shared drive, each user will start sqldeveloper and a directory called sqldeveloper  will be created in their local %APPLICATION_DATA% folder.  This will keep all connections etc unique for all users. 
    You will have to create a link from the S drive to the sqldeveloper.exe if you want a shortcut to start it.  We dont provide it.
    Thanks
    B

  • Help with VARRAY in PL/SQL

    I wrote the below Stored Procedure in a package. I am not able to execute this, can anyone please help
    Package Definition:
    CREATE OR REPLACE PACKAGE "CDS_SUBLIMIT_TYPE_PKG" as
    TYPE COLLATERAL_ARRAY is VARRAY(100) OF NUMBER(29);
    procedure get_original_balance_array_p(in_collateral_id IN NUMBER, l_data OUT COLLATERAL_ARRAY );
    end CDS_SUBLIMIT_TYPE_PKG;
    Package Body:
    CREATE OR REPLACE PACKAGE BODY "CDS_SUBLIMIT_TYPE_PKG" as
    procedure get_original_balance_array_p
    (in_collateral_id IN NUMBER, l_data OUT COLLATERAL_ARRAY ) IS
    CURSOR c_collateral IS
    SELECT collateral_id FROM collateral where rownum < 10;
    BEGIN
    l_data:=COLLATERAL_ARRAY();
    FOR collateral_rec IN c_collateral LOOP
    l_data.extend;
    l_data(l_data.count):=collateral_rec.collateral_id;
    END LOOP;
    l_data.extend;
    l_data(l_data.count):=in_collateral_id;
    END get_original_balance_array_p;
    end CDS_SUBLIMIT_TYPE_PKG;
    Execution:
    declare
    collateral_id number;
    collectionId collateral_array;
    begin
    collateral_id:=55;
    CDS_SUBLIMIT_TYPE_PKG.get_original_balance_array_p(collateral_id, collectionId);
    end;

    collectionId collateral_array;You missed out the package name - it should be
    collectionId cds_sublimit_type_pkg.collateral_array;VARRAYs are good as multivalue columns in database tables, if you're into that (I'm not particularly). In PL/SQL code, nested tables have more functionality, especially in 10g.
    www.williamrobertson.net/documents/collection-types.html

  • Help with Performance tunning PL/SQL

    Hi All,
    I have a PL/SQL procedure, it works fine. No errors, and no bugs. However its taking forever to finish. I am using the concatenation operator (||), and I know its expensive. How can I improve performance to the procedure ?
    Here is the code
    create or replace
    PROCEDURE POST_ADDRESS_CLEANSE AS
    CURSOR C1 IS
    SELECT Z.ROW_ID,
            Z.NAME
    FROM  STGDATA.ACCOUNT_SOURCE Z;
    CURSOR  C2 IS
    SELECT  DISTINCT CLEANSED_NAME || CLEANSED_STREET_ADDRESS ||
            CLEANSED_STREET_ADDRESS_2 || CLEANSED_CITY || CLEANSED_STATE ||
            CLEANSED_POSTAL_CODE AS FULLRECORD
    FROM    STGDATA.ACCOUNT_SOURCE_CLEANSED;
    V_ROWID Number := 1;
    V_FLAG VARCHAR2(30);
    TEMP_ROW_ID VARCHAR2(10) := NULL;
    BEGIN
      -- This loop will update CLEANSED_NAME column in ACCOUNT_SOURCE_CLEANSED table.
      FOR X IN C1 LOOP
        TEMP_ROW_ID := TO_CHAR(X.ROW_ID);
      UPDATE STGDATA.ACCOUNT_SOURCE_CLEANSED A
      SET  A.CLEANSED_NAME = X.NAME
      WHERE A.ROW_ID = TEMP_ROW_ID;
        COMMIT;
      END LOOP;
      -- This loop will update columns EM_PRIMARY_FLAG, EM_GROUP_ID in ACCOUNT_SOURCE_CLEANSED table
      FOR Y IN C2 LOOP
        UPDATE  STGDATA.ACCOUNT_SOURCE_CLEANSED
        SET     EM_GROUP_ID = V_ROWID
        WHERE   CLEANSED_NAME || CLEANSED_STREET_ADDRESS || CLEANSED_STREET_ADDRESS_2 ||
                CLEANSED_CITY || CLEANSED_STATE || CLEANSED_POSTAL_CODE = Y.FULLRECORD;
        UPDATE  STGDATA.ACCOUNT_SOURCE_CLEANSED
        SET     EM_PRIMARY_FLAG = 'Y'
        WHERE   CLEANSED_NAME || CLEANSED_STREET_ADDRESS || CLEANSED_STREET_ADDRESS_2 ||
                CLEANSED_CITY || CLEANSED_STATE || CLEANSED_POSTAL_CODE = Y.FULLRECORD
        AND     ROWNUM = 1;
        V_ROWID := V_ROWID + 1;
        COMMIT;
      END LOOP;
      UPDATE  STGDATA.ACCOUNT_SOURCE_CLEANSED
      SET     EM_PRIMARY_FLAG = 'N'
      WHERE   EM_PRIMARY_FLAG IS NULL;
      COMMIT;
      --dbms_output.put_line('V_ROW:'||V_ROWID);
      --dbms_output.put_line('CLEANSED_NAME:'||Y.FULLRECORD); 
    END POST_ADDRESS_CLEANSE;
    Thanks in advance.
    Message was edited by: Rooney -- added code using syntax highlight

    I was able to modify my code a bit, however I don't see a way of not using loops.
    In the loop, I am updating 2 columns. EM_PRIMARY_FLAG, and EM_GROUP_ID. The data I am working with has duplicate records, and that is why I am using a distinct in the cursor. The requirements are is to make one record a primary record, and the rest are reference records. What makes my record primary is updating column EM_PRIMARY_FLAG with a 'Y', and updating EM_GROUP_ID with a number combines all duplicate records into a group.
    In the procedure, I am getting the distinct records, looping through each one, and then doing 2 updates:
    1 - Update EM_PRIMARY_FLAG to 'Y' where rownum = 1, this will set one record to be primary
    2 - Update EM_GROUP_ID to a number (V_ROWID := V_ROWID + 1) where V_ROWID starts from 1, to group all records into a set.
    Here is my latest code after modifying it:
    create or replace
    PROCEDURE POST_ADDRESS_CLEANSE AS
    CURSOR  C1 IS
    SELECT      DISTINCT NVL(CLEANSED_NAME, '') AS NAME_CLEANSED,
                      NVL(CLEANSED_STREET_ADDRESS, '') AS ADDRESS_CLEANSED,
                      NVL(CLEANSED_STREET_ADDRESS_2, '') AS ADDRESS2_CLEANSED,
                      NVL(CLEANSED_CITY, '') AS CITY_CLEANSED,
                      NVL(CLEANSED_STATE, '') AS STATE_CLEANSED,
                      NVL(CLEANSED_POSTAL_CODE, '') AS POSTAL_CODE_CLEANSED
    FROM        STGDATA.ACCOUNT_SOURCE_CLEANSED;
    V_ROWID Number := 1;
    V_FLAG VARCHAR2(30);
    TEMP_ROW_ID VARCHAR2(10) := NULL;
    BEGIN
        UPDATE STGDATA.ACCOUNT_SOURCE_CLEANSED A
        SET  A.CLEANSED_NAME = (SELECT   Z.NAME
                                                       FROM     STGDATA.ACCOUNT_SOURCE Z
                                                       WHERE    Z.ROW_ID = (SELECT  TO_NUMBER(B.ROW_ID)
                                                                                           FROM    STGDATA.ACCOUNT_SOURCE_CLEANSED B
                                                                                           WHERE   B.ROW_ID = A.ROW_ID));
        COMMIT;
      -- This loop will update columns EM_PRIMARY_FLAG, EM_GROUP_ID in ACCOUNT_SOURCE_CLEANSED table
      FOR Y IN C1 LOOP
        UPDATE   STGDATA.ACCOUNT_SOURCE_CLEANSED
        SET          EM_GROUP_ID = V_ROWID
        WHERE    CLEANSED_NAME = Y.NAME_CLEANSED
        AND          CLEANSED_STREET_ADDRESS = Y.ADDRESS_CLEANSED
        AND          CLEANSED_STREET_ADDRESS_2 = Y.ADDRESS2_CLEANSED
        AND          CLEANSED_CITY = Y.CITY_CLEANSED
        AND          CLEANSED_STATE = Y.STATE_CLEANSED
        AND          CLEANSED_POSTAL_CODE = Y.POSTAL_CODE_CLEANSED;
        UPDATE  STGDATA.ACCOUNT_SOURCE_CLEANSED
        SET     EM_PRIMARY_FLAG = 'Y'
        WHERE   CLEANSED_NAME = Y.NAME_CLEANSED
        AND     CLEANSED_STREET_ADDRESS = Y.ADDRESS_CLEANSED
        AND     CLEANSED_STREET_ADDRESS_2 = Y.ADDRESS2_CLEANSED
        AND     CLEANSED_CITY = Y.CITY_CLEANSED
        AND     CLEANSED_STATE = Y.STATE_CLEANSED
        AND     CLEANSED_POSTAL_CODE = Y.POSTAL_CODE_CLEANSED
        AND     ROWNUM = 1;
        V_ROWID := V_ROWID + 1;
      END LOOP;
      COMMIT;
      UPDATE  STGDATA.ACCOUNT_SOURCE_CLEANSED
      SET     EM_PRIMARY_FLAG = 'N'
      WHERE   EM_PRIMARY_FLAG IS NULL;
      COMMIT;
    END POST_ADDRESS_CLEANSE;
    Thanks
    Message was edited by: Rooney - Just added the code in SQL block using syntax highlight.

  • Help with inserting values to sql database

    Hello everyone I am having this problem with how to fill my values in my sql statement, if you look below you will notice i have set up the values to be the length of the arr (arrayList).
    could someone please let me now how i should put there values in.
    thanks for yr time
    piper3
      try {
                                                    String data = "jdbc:odbc:myProject";
                                                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                                        Connection con = DriverManager.getConnection(data,"","");
                                                 StringBuffer sb = new StringBuffer();
                                                 Iterator it1 = arr.iterator();
                                                 while (it1.hasNext())
                                                      if (sb.length() > 0)
                                                           sb.append(",");
                                                           sb.append(it1.next());
                                                      //takes the items of the arInterim
                                                      //int iCountInterim = arInterim.size();
                                                      int er = arr.size();
                                                      String sInterim = new String();
                                                      String sql = new String();
                                                      for(int i2 = 0; i2 < er; i2++){
                                                           sInterim = sInterim + sQuestion;
                                                           if(i2 < (er-1)){
                                                                sInterim = sInterim + sComma;
                                                           sql = "INSERT into Ben (" + sb.toString() + ") values (" + sInterim + ")";
                                                           System.out.println(sql);
                                                           PreparedStatement prepStmt = con.prepareStatement(sql);
                                                           /*prepStmt.setString(1, "hello");
                                                           prepStmt.setString(2, "hi");
                                                           prepStmt.setString(3, "bye");
                                                           prepStmt.executeUpdate();
                                                           prepStmt.close();*/
                                                      con.close();               
                                                 } catch (Exception e1) {
                                                             System.err.println("Got an exception! ");
                                                             System.err.println(e1.getMessage());
                                                      //System.out.println();//.size());//tempkey+"\n"+tempvalue);

    you should write a prepared statement like this:
    PreparedStatement updateSales = con.prepareStatement(
    "UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");
    where "?" is a placeholder for the values you want to use.
    Then later when you want to actually update your database, first set the placeholders to your values (stored in your array for example) using a statement like this:
    updateSales.setString(2, "Colombian");
    //sets the 2. placeholder in the statement to the value "Colombian"
    after having set all placeholders to a specific value, execute your statement:
    updateSales.executeUpdate();
    your code should like:
    sql = "INSERT into Ben values (?,?,?)";
    PreparedStatement prepStmt = con.prepareStatement(sql);
    prepStmt.setString(1, "hello");
    prepStmt.setString(2, "hi");
    prepStmt.setString(3, "bye");
    prepStmt.executeUpdate();
    prepStmt.close();
    HTH
    Christine

  • Help With SUBSTR in dynamic SQL statement

    Following is the dynamic SQL statement.
    EXECUTE IMMEDIATE 'UPDATE table_name pml
    SET pml.'|| con_fields.field ||' = SUBSTR(pml.'||con_fields.field||' ||'' ''||
    (SELECT pml1.'||con_fields.field||'
    FROM table_name pml1
    WHERE pml1.grp_id = '||los_concats.grp_id ||'
    AND pml1.row_id = '||los_concats.row_id||'
    AND pml1.loser_flg = ''Y''),1, '||con_fields.max_length||')
    WHERE pml.grp_id = '||los_concats.grp_id ||'
    AND pml.loser_flg IS NULL ';
    what it does is that it updates a particular field. This field is concatenated by a field of a similar record.
    My problem is with SUBSTR function. Since I am concatenating fields I do not want the field to be updated greater than max_length on that field, the reason why I use SUBSTR. the select query inside SUBSTR works alright with one of the AND condition in a WHERE clause not present. When I add that additional condition it gives me this error.
    ORA-00907: missing right parenthesis.
    Is there any way to get around this problem. Does SQL has other than SUBSTR function which can limit the character length.
    Appreciate it.

    The other alternative I thought about was to do this first
    EXECUTE IMMEDIATE 'SELECT pml.'||con_fields.field||'
    FROM table_name pml
    WHERE pml.grp_id = '||los_concats.grp_id||'
    AND pml.row_id = '||los_concats.row_id||'
    AND pml.loser_flg = ''Y''
    ' INTO v_concat_field;
    write into the variable v_concat_field and then use it into the previous script.
    But on this I get SQL Command not properly terminated, I don't get it Why?
    Donald I tried with your suggested script. It works fine with one of the conditions eliminated. I don't understand what the error trying to say?
    Thanks

  • Help with Crystal Reports changing SQL Server

    I am doing a web site cutover to a new server for a client and have the server up and running using crystal reports server xi r2 sp2 under windows server 2003r2 32bit.
    When I run a report via the webpage it generates a blank page.
    I've edited the old web developers crystal report files and updated the database path howerver when i type in the new SQL server and authenticate to it using the SA account  it then pops up a window asking me to enter values
    has items such as
    @sUserID
    @sSubUserID
    @iSessionID
    etc
    the only way i can continue through this is to check a box for each value 'set to null' which i dont' think is correct.
    What values should I be putting in these areas or should I be getting this infomation from the previous developer?
    much appreciated

    Hello,
    I don't recognize those variables as CR ones so it's likely something the original developer is setting in code.
    You'll have to discuss with that person.
    If your have SDK issues then post your question to one of the .NET or Java SDK forums.
    Thank you
    Don

  • Help with Flex - PHP - and SQL Server

    Good afternoon,
    I have been working on this problem for over a week and am at
    my wit's end. I am trying to create an application that will allow
    me and my fellow statisticians to share code easily. The
    technologies at my disposal are Flex, PHP and SQL Server 2005. The
    web server is IIS. I have downloaded and installed the PHP driver
    for SQL Server 2005 and am able to query the database and generate
    XML. The problem I'm having is that I can't return the XML from PHP
    to Flex.
    If I execute the php code in a web browser and view the
    source, it looks like XML. I can then cut and paste the exact same
    code into an xml file and read it in from the harddisk and the tree
    will populate. Can anyone please help me? I don't have flex builder
    so I it's hard for me to use trace and view what is going on.
    Thanks in advance,
    Eric Graves

    Thanks for the suggestion. I have tried every permutation of
    e4x path notation I can think of. You're right, you're not supposed
    to need the root level as that's supposed to be returned in the
    result. So you should only need to reference first level after the
    root. When I do this and launch the .SWF I get a completely empty
    tree.
    I think the problem lies somewhere in my understanding of
    what format Flex needs returned from a HTTPRequest. It's my
    understanding that it just needs to be XML. As far as I can tell,
    that's what I'm sending it. On the PHP side, does it have to be
    cast a special way? Everything I've seen just shows people using
    ECHO to output the XML data.

  • Help with a really simple SQL statement

    Hi All
    I'm relatively new to SQL and can't get my head round what I believe to be a really simple problem.
    I have a table I want to query called locations. We use locations to mean groups and regions as well as people s ofr example:
    TABLE: LOCATION
    IDENTIFIER----------NAME-----------------PART_OF
    101--------------------USER A---------------123
    123--------------------GROUP A-------------124
    etc
    What I'm trying to write is a statement that will return the 'PART_OF' as the 'NAME' rather than the ID number if the ID = 101.
    I was wondering if a nested select statement would do (select as select etc) but just can't get my head round it!
    Any ideas?
    TIA. Jake.

    Hi Jake,
    It's not clear what you are looking for. If USER A is just Part of GROUP A, a self-join will do:
    SQL> with loc as (select 101 locid, 'USER A' locname, 123 part_of from dual
                 union all
                 select 123 locid, 'GROUP A' locname, 124 part_of from dual
                 union all
                 select 124 locid, 'REGION A' locname, null part_of from dual)
    -- End of test data
    select l1.locid, l1.locname, l2.locname part_of
      from loc l1, loc l2
    where l2.locid(+) = l1.part_of
         LOCID LOCNAME  PART_OF
           101 USER A   GROUP A
           123 GROUP A  REGION A
           124 REGION A        
    3 rows selected.But if you want USER A to be part of REGION A, then you need a hierarchia lquery:
    SQL> with loc as (select 101 locid, 'USER A' locname, 123 part_of from dual
                 union all
                 select 123 locid, 'GROUP A' locname, 124 part_of from dual
                 union all
                 select 124 locid, 'REGION A' locname, null part_of from dual)
    -- End of test data
    select l1.locid, l1.locname, connect_by_root(locname) part_of
      from loc l1
    start with part_of is null
    connect by prior locid = part_of
         LOCID LOCNAME  PART_OF
           124 REGION A REGION A
           123 GROUP A  REGION A
           101 USER A   REGION A
    3 rows selected.Regards
    Peter

  • Help with Date function in sql query....

    My question I guess is really 2...I'm trying to use the date function as a comparison in my WHERE clause in my sql command.
    1. My date format is dd-MMM-yy eg. (01-Apr-06) ... my problem is the Apr is lower case where my field in the database is 01-APR-06 so when I compare 01-Apr-06 to 01-APR-06 is doesnt find any rows. Is there away that I can make the Apr all upper case so that it is APR.
    2. My second problem is getting this "date" field to work in my sql stmt I keep getting errors and it works fine if I take my attempts at trying to compare the date.
    --------------Date Code----------------------------------------------------------
    <%!
    String getFormattedDate(java.util.Date d)
    SimpleDateFormat simpleDate = new SimpleDateFormat("01-MMM-yy");
    return simpleDate.format(d);
    %>
    <%
    java.util.Date d = new java.util.Date();
    String dateString = getFormattedDate (d);
    %>
    ---------------------------Sql statment------------------------------------------
    ResultSet rset = stmt.executeQuery ("SELECT name " + " FROM table where rdate = '01-APR-06' order by name ");
    Currently Im just hard coding the date but I need to make it so it uses the date code...so....
    rdate should equal the date from the formatted date in upper case
    something like
    rdate = <%= dateString %>
    Thanks in advance for any ideas anyone may have...

    There are sql functions upper & lower.
    SELECT name  FROM table where upper(rdate) = '01-APR-06' order by name Or you could convert the date to a string, and use the toUpperCase & toLowerCase java.lang.String methods. It doesn't make much of a difference--do you want the java compiler to do the string conversion or the database?

  • Need help with an XML-based SQL query

    Hello, everyone:
    I get 'no rows selected' from the following queries:
    SELECT extractValue((p.entity_types_xml), '/entities/test[a=fagioli]')
    FROM entity_types p
    WHERE
    existsNode(p.entity_types_xml,
    '/entities/test/text()') = 1;
    SELECT extractValue((p.entity_types_xml), '/entities/test/text()')
    FROM entity_types p
    WHERE
    existsNode(p.entity_types_xml, '/entities/test/text()') = 1;
    SELECT
    extractValue(p.entity_types_xml,'/entities/ARFinance-elem/entity-type')
    FROM entity_types p
    WHERE
    existsNode(p.entity_types_xml,'/entities/ARFinance-elem/ARFinanceTBD/text()') = 1;
    where the entity_types table looks like this:
    SQL> desc entity_Types;
    Name Null? Type
    ENTITY_TYPES_ID NOT NULL VARCHAR2(36)
    ENTITY_TYPES_XML NOT NULL XMLTYPE
    CLIENT_ID VARCHAR2(30)
    and the XML fragment looks like this:
    +++++++++++++++++++++++++++++++++++++
    <?xml version="1.0" encoding="UTF-8"?>
    <entities
    xmlns="http://www.thirdpillar.com/xml/namespace/aom/entity"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.thirdpillar.com/xml/namespace/aom/entity ../generated/denormalized-schema.0.xsd">
    <test a="fagioli">pasta</test>
    <ARFinance-elem>
    <uid b="pasta">123</uid>
    <entity-type><![CDATA[ARFinance]]></entity-type>
    <ARFinanceTBD>tobedetermined</ARFinanceTBD>
    </ARFinance-elem>
    ++++++++++++++++++++++++++++++++++++++++++++
    As you can see, there is data in /entities/test[@a] as well as /entities/test/text(),
    so why aren't any of the queries returning the preceding XML fragment? Suggestions welcome and appreciated....
    Regards,
    Oswald
    ps: I'm sure I've overlooked something simple.

    Oswald,
    I think you need to add the namespace
    select extractValue(.....','xmlns:xsi="http://www.thirdpillar.com/xml/namespace/aom/entity"')
    from entity_types p

Maybe you are looking for

  • Error while using query in Dataset to retreive unique data

    Hi, I have added the below query in the EBS dataset to retrieve only unique applications as APPLICATION_NAME column has some duplicate data. I imported data to DB. select distinct(APPLICATION_NAME) as NAME from APPLICATION But, when I try to filter o

  • Iweb photo gallery -- download option unwanted

    I just created my first site using iweb and put a photo gallery on there. I noticed that there is a download option which I DO NOT want on there!! I want to make my photo galleries view ONLY! Is there a way to change the settings?? Thanks!

  • Connect to SharePoint web service using the XML / Web Service connector

    Hi experts, I am currently trying to display my SharePoint list in Crystal Report. Therefore my plan is to use a SharePoint web service to get the data and paste them to the Crystal Report. Is it possible to use the "XML and Web services" connector o

  • [nForce] no audio on disk or image when burning a dvd movie

    i've recently bought a K7N2 Delta I lsr and since i've had this i have never been able to burn a dvd movie no matter what i try. I've started from scratch trying with just the AC-97 audio drivers installed and downloaded the latest nforce audio drive

  • Default Profit centre not picked up

    Hi, Document splitting is activated. Now i have assigned one bank account to one profit centre '1210' in tcode 3keh I am posting customer receipt. Customer is in profit centre '1100' I have defined zero balance clearing account - 20010010 Now when i