Should i use nested SQL Statements? or PL/SQL?

here is my table:
let's call this table total_stats, with 2 fields (columns) Date and Total.
Row | Total
ROW1 | 12508
ROW2 | 12526
I am going crazy trying to write some sql or pl/sql that will give me the following results: the result of row2Total - row1Total. I need the delta of the two Total's rows.
Is there an easy way to do this without writing multiple nested sql statments?
Should i write a procedure that uses cursors to help me get my end result?
thanks

Use analytic functions - LAG and LEAD - to access other rows in the result set in a current row. This should get you started:
SQL> create table total_stats as
  2  select sysdate-1 as some_date, 12508 as some_value from dual
  3  union all
  4  select sysdate as some_date, 12526 as some_value from dual
  5  /
Table created.
SQL> select * from total_stats;
SOME_DATE  SOME_VALUE
12/11/2007      12508
13/11/2007      12526
2 rows selected.
SQL> select
  2    some_date,
  3    some_value as this_dates_value,
  4    lag(some_value) over (order by some_date) as the_previous_dates_value
  5  from
  6    total_stats
  7  /
SOME_DATE  THIS_DATES_VALUE THE_PREVIOUS_DATES_VALUE
12/11/2007            12508
13/11/2007            12526                    12508
2 rows selected.

Similar Messages

  • How to create nested CASE statements in PL/SQL

    Can anyone please tell how to create Nested CASE statements in PL/SQL with proper syntax?
    It would be better if you can help with an example.
    Thank you!

    Something like this:
    SQL> set serveroutput on
    SQL> declare
      2    v1 number := 2;
      3    v2 varchar2(1) := 'C';
      4  begin
      5    case v1
      6      when 1 then dbms_output.put_line('First');
      7      when 2 then begin
      8                    case v2
      9                      when 'A' then dbms_output.put_line('Found A');
    10                      when 'B' then dbms_output.put_line('Found B');
    11                      when 'C' then dbms_output.put_line('Found C');
    12                      else dbms_output.put_line('NONE');
    13                    end case;
    14                  end;
    15      else dbms_output.put_line('Else');
    16    end case;
    17  end;
    18  /
    Found C
    PL/SQL procedure successfully completed
    SQL> If you have further doubts regarding syntax you can read the docs on the Case statement here:
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/case_statement.htm

  • Multiple SQL statements in Init SQL in WLS 8.1

    How to seperate multiple SQL statements in Init SQL text box ?
    For example, I want to enter following two SQL statements. How do I seperate them.
    I tested with / and ; as seperator, but did not worked..
    alter session set nls_date_format = 'MM/DD/YYYY'
    set role xxx_role identified by xxxx

    Mahendra wrote:
    Thanks Joe.
    Following worked for Oracle 8.1.7Good news.
    but did not for 8.0.6
    SQL BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''MM/DD/YYYY''';
    EXECUTE IMMEDIATE 'SET ROLE xxx identified xxx'; end;
    Do you know 8.0.6 syntax ?You might try asking oracle, but note that no one is supporting that old version
    of Oracle any longer...
    Joe
    >
    Mahendra
    Joe Weinstein <[email protected]> wrote:
    Hi.
    I found the syntax, I think. Try this:
    BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = 'MM/DD/YYYY'';
    EXECUTE IMMEDIATE 'SET ROLE <<role name>> identified
    by <<pwd>>';END;
    Joe
    Mahendra wrote:
    Still getting following exception.
    <Feb 19, 2004 1:47:58 PM EST>
    <Warning>
    <JDBC> <BEA-001164>
    <Unable to initialize connection in pool "XXXX".
    Initialization
    SQL = "BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole xxxx_role
    identified by
    xxxx; END;".
    Received exception: "java.sql.SQLException: ORA-06550: line 1,column7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of thefollowing:
    begin declare exit for goto if loop mod null pragma raise
    return select update while <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql commit <a single-quoted SQL string>
    The symbol "update was inserted before "ALTER" to continue.
    ORA-06550: line 1, column 61:
    PLS-00103: Encountered the symbol "ROLE" when expecting one of thefollowing:
    transaction
    ".>
    <Feb 19, 2004 1:47:59 PM EST> <Notice> <WebLogicServer> <BEA-000355><Thread "Li
    Joe Weinstein <[email protected]> wrote:
    Mahendra wrote:
    Thanks for reply, but that did not worked.
    Get following exception
    Unable to initialize connection pool "POOL_NAME".
    Initialization SQL = "Select count(*) from ""SQL BEGIN alter sessionset nls_date_format
    = 'MM/DD/YYYY'; set role xxx_role identified by xxxx; END;"". Receivedexception:
    "java.sql.SQLException: ORA-00972: identifier is too long
    Since we have not given SQL before that statement, BEA is treating
    statment "SQL Begin ....." as a table name.
    Then I tried by putting SQL out side quotes, like SQL "Begin .....end;" but the
    same error.
    Is there any way around it ?
    MahendraHi. The full string you should enter into the console when you define
    the
    initSQL parameter is:
    SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; set role
    xxx_role identified by xxxx; END;
    Let me know...
    Joe
    Joe Weinstein <[email protected]> wrote:
    Mahendra wrote:
    How to seperate multiple SQL statements in Init SQL text box ?
    For example, I want to enter following two SQL statements. How do
    I
    seperate them.
    I tested with / and ; as seperator, but did not worked..
    alter session set nls_date_format = 'MM/DD/YYYY'
    set role xxx_role identified by xxxxThis will always be DBMS-specific. If this is for oracle, you can
    try:
    "SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole
    xxx_role identified by xxxx; END;"
    Joe

  • Run sql statements in PL/Sql Developer without installing Oracle database?

    Hi all,
    I wish to ask is there any possibility to run Run sql statements in PL/Sql Developer without installing Oracle database?
    Regards.

    Hello Jimmy,
    this is the forum for the tool SQL Developer and, as the title says, *(Not for general SQL/PLSQL questions)*.
    PL/Sql Developer is not an Oracle tool, but from allound allroundautomations.
    And you need access to a database to run SQL statements. This does not need to be one installed by yourself.
    Regards
    Marcus

  • Using an NDS statement for a SQL stament run only once in a proceudure

    Hi,
    We're using Oracle 11.1.0.7.0.
    I'm going through code written by someone else. In this package they're using NDS for every SQL call whether it gets called multiple times or just once. Is that a good thing?
    I thought NDS was only reserved for SQL statements that get called over and over again in a procedure with possible varying 'WHERE clause' variables and so on...
    Is there ANY benefit to using NDS for SQL queries called only once in a procedure?
    Thanks

    There is no benefit unless you want to turn PL/SQL into SQL*Plus (parse once, run once)
    Procedures exist to make sure : parse at compile time, run many times.
    The code is shooting itself in its own foot.
    Or the developer must have got hold of Tom Kyte's unpublished one chapter book 'How to write unscalable applications'.
    Sybrand Bakker
    Senior Oracle DBA

  • SQL statement works with SQL/Plus - but not with ODBC

    Hi all,
    I have a rather copmplex SQL statement:
    BEGIN
    UPDATE ContentDataTable
    SET SYMBOLIC_PATH_PARENT = N'/Test',
    SYMBOLIC_NAME = N'HAWK01.GIF',
    VERSION_NUMBER = 1 +
    SELECT MAX(VERSION)
    FROM
    (SELECT MAX(VERSION_NUMBER) AS VERSION
    FROM ContentDataTable WHERE
    SYMBOLIC_PATH_PARENT = N'/Test' AND
    SYMBOLIC_NAME = N'HAWK01.GIF'
    UNION
    SELECT MAX(VERSION_NUMBER) AS VERSION
    FROM RevisedContentDataTable WHERE
    SYMBOLIC_PATH_PARENT = N'/Test' AND
    SYMBOLIC_NAME = N'HAWK01.GIF'))
    WHERE SYMBOLIC_PATH_PARENT = N'/Test' AND SYMBOLIC_NAME = N'HAWK02.GIF' AND VERSION_NUMBER = 1;
    END;
    It works fine in SQL/Plus or SQL Worksheet and does what it should do ;-)
    But when using it via ADO (ODBC Driver) I get the following error:
    PLS-00103 found 'string' but expected one of the following: 'string'"}
    Any idaes?
    Thanx,
    Christian
    null

    Pardon my ignorance, but what's the significance of the N'<string>' construction? That's not one I'm familar with.
    Justin

  • Possible to do "grant" sql statement in Native SQL?

    We have a need to do a grant of access from one of our systems out for various applications.  In order for this to work we need to run a grant access command on the table and are trying to put a wrapper around this so we can use an abap.  Below is the code I am unit testing.  Two questions.  First, can a grant be done via native SQL in abap?  Second, if it can be done, what is the error with the logic where I am trying to put in the table name via a parameter.
    REPORT  ZLJTEST2.
    tables dd02l.
    DATA scarr_carrid TYPE dd02l-tabname.
    SELECT-OPTIONS s_carrid for dd02l-tabname no intervals.
    DATA s_carrid_wa LIKE LINE OF s_carrid.
    DATA name TYPE c LENGTH 20.
    TRY.
        EXEC SQL.
          CREATE FUNCTION selfunc( input CHAR(20) )
            RETURNING char(20);
            DEFINE output char(20);
            set schema sapr3;
            grant select on table input to group infouser;
            RETURN output;
            END FUNCTION;
        ENDEXEC.
        LOOP AT s_carrid INTO s_carrid_wa
                         WHERE sign = 'I' AND option = 'EQ'.
          TRY.
             EXEC SQL.
                EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low,
                                           OUT :name )
              ENDEXEC.
              WRITE: / s_carrid_wa-low, name.
            CATCH cx_sy_native_sql_error.
              MESSAGE `Error in procedure execution` TYPE 'I'.
          ENDTRY.
        ENDLOOP.
        EXEC SQL.
          DROP FUNCTION selfunc;
        ENDEXEC.
      CATCH cx_sy_native_sql_error.
        MESSAGE `Error in procedure handling` TYPE 'I'.
    ENDTRY.

    Hi,
    Yes it is posible.
    I made one program like you want. But it need very long code.
    Here I explain the idea:
    1. Create Screen with input TEXT EDIT CONTROL.
        This is for input SQL Statement.
    2. Get SQL Statement from Text Edit Control using method <b>get_text_as_r3table</b>.
    3. Now we need to separate SQL Statement into different table.
        We Separate SELECT, FROM, WHERE, GROUP, HAVING, ORDER, etc.
    4. We need dynamic internal table to store the data.
    5. Select the data according SQL statement.
          SELECT (IT_SELECT)
            into corresponding fields of table  <dyn_table>
          FROM (IT_FROM)
          WHERE (IT_WHERE)
          GROUP BY (IT_GROUP)
          HAVING (IT_HAVING)
          ORDER BY (IT_ORDER).
    6. Display our data using ALV GRID
    Hopefully it will help you.
    Regards,

  • Variables & dynamic sql statements in PL/SQL

    Hi All,
    I'm sure I am missing something really simple, but I can't figure it out...
    In a procedure, I'm trying to 'build' a sequence name from a parameter (table name), and then select the nextval into another variable to be used later. But I don't seem to be doing it correctly...
    First I created a var to hold the full sequence name (table_name_seq.nextval) like this:
    v_Sequence_Name := '"'||param_table_name||'_Seq".nextval';This seems to work correctly as I have output the value and I get what I am expecting. Next I try to use the new variable in a select statement like so:
    -- I've tried many variations here, but none have worked
    select v('v_Sequence_Name') into v_Sequence_ID from dual;I end up with a Null I think (because I insert the value into a test table).
    Any ideas what I am doing wrong?
    TIA,
    Corey

    dynamic query in pl/sql needs to be executed using exec. immediate statement or the dbms_sql package.
    here's what you can do :
    execute immediate 'select '|| v_sequence_name ||' from dual' into v_sequence_id;

  • SQL statement inside a SQL statement

    Hello,
    I'm trying to write a SQL statement to a field in a table ( so that i can store some sql statements in a table) For the most part this code works fine (where string1 is the statement):
    updatestring1 = "update [@SQLSTATEMENTS] set [U_statement] = '" & qstring1.ToString & "' where [Code] = " & row
    oRecordSet.DoQuery(updatestring1)
    but when the statement that i want to save contains a WHERE clause that refernces a string (enclosed by single quotes), the update query fails - because of the quotes i think.
    I'm thinking i might be able to use different symbols in the statement to signify that it is a string but i'm not sure...
    Is there a better way to write the query to a field in a table ? maybe one that doesn't require an update query ? I'm pretty new to SDK (and SQL), so any advice will help - even if it's something really obvious...
    Thanks!

    I am not sure why you need to save SQL queries in the table but, you need to follow up a single quote with another single quote. for example look at the following sql string
    update customer set custname  = 'Customer'' A'  where custid = 'CustA'
    'IS correct
    However the following will fail
    update customer set custname  = 'Customer' A'  where custid = 'CustA'
    Message was edited by: Indika Dekumpitiya

  • Can I use the `deny` statements is a SQL database

    I have a web-app that I will need to scale to large proportions. In this web-app, I have a database in which some clients should not have access to specif tables. Can I use `deny` statements on an Azure SQL databases? Like this:
    deny select on a_table to a_user

    Hi James,
    Yes you can use DENY statements. Please see
    this link for more information on the usage of DENY statements.
    Thanks
    Silvia Doomra

  • What should I use BCS or directly connect to sql server to get data.

    Hi All,
    I have a requierment where the data is in the sql server.
    We  are using sharepoint webpart to show the data from the sql.
    Should i get the data from the sql server using connection string.
    Is there any better way to get data from Sql server table and show that in the custom asp.net form.
    Regards
    Vinod

    As I see the questions is in SharePoint 2013 forum.
    Assuming you have SharePoint 2013/2010, you can create Create/Read/Update/Delete operations on directly sql table using BCS service of SharePoint. That will save you default development of web part and handle all information properly.
    If you don't want to use BCS and sql (not sharepoint sql) information required, you can create custom web part/app part.
    Thanks, Ashish | Please mark a post helpful/answer if it is helpful or answer your query.

  • Using a string as sql statement in PL/SQL

    Hi there,
    I have a function which returns a part of a query depending on some conditions.
    FUNCTION GET_REPORT_TYPE(in_report_type IN NUMBER)
    RETURN VARCHAR2
    AS
    reporttype varchar2(50);
    BEGIN
    CASE in_report_type
    WHEN 0 THEN
    reporttype := 'C1.DATE_CLOSED != NULL';
    WHEN 1 THEN
    reporttype := 'C1.DATE_CLOSED := NULL';
    WHEN 2 THEN
    reporttype := '';
    END CASE;
    RETURN reporttype;
    END GET_REPORT_TYPE;
    Now in my procedure I would like to put this returned value in an AND clause of my query:
    procedure get_cpl(p_cursor OUT rst_cur, searchcode IN VARCHAR2, reporttype IN VARCHAR2)
    is
    begin
    open p_cursor for
    SELECT C1.CIPIDI_NR,
    C1.CIPIDI_NAME,
    C2.TEAM_MEMBER
    FROM TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
    WHERE C1.CIPIDI_NR LIKE searchcode
    AND C1.CIPIDI_NR = C2.CIPIDI_NR (+);
    AND reporttype; -- HERE I WOULD LIKE TO USE WHAT THE FUNCTIONS RETURNED
    end get_cpl;
    How can I can I use reporttype to function as a part of the query? Thanks a lot
    Chris

    scott@ORA92> -- test data:
    scott@ORA92> SELECT * FROM tbl_cipidi
      2  /
    CIPIDI_NR CIPIDI_NAME DATE_CLOS
             1 name1       30-MAY-05
             1 name2
    scott@ORA92> SELECT * FROM tbl_team_members
      2  /
    CIPIDI_NR TEAM_MEMBER
             1 team1
    scott@ORA92> -- function:
    scott@ORA92> CREATE OR REPLACE FUNCTION GET_REPORT_TYPE
      2    (in_report_type IN NUMBER)
      3    RETURN            VARCHAR2
      4  AS
      5    reporttype       varchar2(50);
      6  BEGIN
      7    CASE in_report_type
      8        WHEN 0 THEN reporttype := 'C1.DATE_CLOSED IS NOT NULL';
      9        WHEN 1 THEN reporttype := 'C1.DATE_CLOSED IS NULL';
    10        ELSE reporttype := '1 = 1';
    11    END CASE;
    12    RETURN reporttype;
    13  END GET_REPORT_TYPE;
    14  /
    Function created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- packaged with procedure:
    scott@ORA92> CREATE OR REPLACE PACKAGE your_pkg
      2  AS
      3    TYPE rst_cur IS REF CURSOR;
      4    procedure get_cpl
      5        (p_cursor   OUT rst_cur,
      6         searchcode IN  VARCHAR2,
      7         reporttype IN  VARCHAR2);
      8  END your_pkg;
      9  /
    Package created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY your_pkg
      2  AS
      3    procedure get_cpl
      4        (p_cursor   OUT rst_cur,
      5         searchcode IN  VARCHAR2,
      6         reporttype IN  VARCHAR2)
      7    is
      8    begin
      9        OPEN p_cursor FOR
    10        'SELECT C1.CIPIDI_NR,
    11             C1.CIPIDI_NAME,
    12             C2.TEAM_MEMBER
    13         FROM      TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
    14         WHERE  C1.CIPIDI_NR = :b_searchcode
    15         AND      C1.CIPIDI_NR = C2.CIPIDI_NR (+)
    16         AND ' || get_report_type (reporttype)
    17        USING searchcode;
    18    end get_cpl;
    19  END your_pkg;
    20  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- tests:
    scott@ORA92> VARIABLE g_ref REFCURSOR
    scott@ORA92> SET AUTOPRINT ON
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 0)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name1       team1
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 1)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name2       team1
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 2)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name1       team1
             1 name2       team1
    scott@ORA92>

  • Should I use a CASE statement to accomplish or something else

    So I have the following query right now
    select *
        --bulk collect into possession_leaders
        from
               select    distinct
                         opt.team_id,
                         sch.game_code,
                         sch.game_code_1032,
                         sch.home_team_id_1032,
                         sch.home_team_id,
                         sch.home_team_name,
                         sch.home_team_nickname,
                         sch.home_team_abbrev,
                         sch.away_team_id_1032,
                         sch.away_team_id,
                         sch.away_team_name,
                         sch.away_team_nickname,
                         sch.away_team_abbrev,
                         opt.possession,
                         rank () over (order by possession desc) as rankings_order
              from 
                       customer_data.cd_soccer_schedule sch,
                       soccer.soccer_optical_team_gm_stats opt
              where    sch.game_code = opt.game_code
              and      sch.season_id = 200921
              and      opt.possession is not null
              order by rankings_order asc
            )It outputs the following (Sorry for it being so cramped together):
    **Note: Columns are in the same order as the query, I didn't post the column names b/c everything would look even sloppier then it does
    1     5358     870986     2009050606     6     5359     Kansas City     Wizards     KC     5     5358     D.C.     United     DC     69.5%     1
    2     5354     870945     2009040501     1     5354     Chicago     Fire     Chi     10     5362     New York     Red Bulls     RB     58.1%     2
    3     5721     870983     2009050211     11     5363     San Jose     Earthquakes     SJ     17     5721     Chivas USA          Chv     56%     3
    4     5360     870984     2009050207     7     5360     Los Angeles     Galaxy     LA     10     5362     New York     Red Bulls     RB     55.6%     4
    5     5361     870961     2009041705     5     5358     D.C.     United     DC     9     5361     New England     Revolution     NE     55.4%     5
    6     5362     870988     2009050810     10     5362     New York     Red Bulls     RB     11     5363     San Jose     Earthquakes     SJ     50.1%     6
    7     5363     870988     2009050810     10     5362     New York     Red Bulls     RB     11     5363     San Jose     Earthquakes     SJ     49.9%     7
    8     5358     870961     2009041705     5     5358     D.C.     United     DC     9     5361     New England     Revolution     NE     44.6%     8
    9     5362     870984     2009050207     7     5360     Los Angeles     Galaxy     LA     10     5362     New York     Red Bulls     RB     44.4%     9
    10     5363     870983     2009050211     11     5363     San Jose     Earthquakes     SJ     17     5721     Chivas USA          Chv     44%     10
    11     5362     870945     2009040501     1     5354     Chicago     Fire     Chi     10     5362     New York     Red Bulls     RB     41.9%     11
    12     5359     870986     2009050606     6     5359     Kansas City     Wizards     KC     5     5358     D.C.     United     DC     30.5%     12What i'm trying to do is basically have the output formated so that when the team_id column matches the either the home_team_id or away_team_id colum i want the following columns to be renamed as:
    so if team_id = home_team_id for example then I want the following...
    sch.home_team_id_1032 as team_code_1032,
    sch.home_team_id as team_code,
    sch.home_team_name as team_name,
    sch.home_team_nickname as team_nickname,
    sch.home_team_abbrev as team_abbrev
    and then the away team columns would be...
    sch.away_team_id_1032 as opp_team_code_1032,
    sch.away_team_id as opp_team_code,
    sch.away_team_name as opp_team_name,
    sch.away_team_nickname as opp_team_nickname,
    sch.away_team_abbrev as opp_team_abbrev
    and same thing vice versa if the team_id column matches the away_team_id
    How is the best way to go about this? W/a case statement? and if so can someone please post the logic/

    Hi,
    user652714 wrote:
    So I have the following query right now
    select *
    --bulk collect into possession_leaders
    from
    select    distinct
    opt.team_id,
    sch.game_code,
    sch.game_code_1032,
    sch.home_team_id_1032,
    sch.home_team_id,
    sch.home_team_name,
    sch.home_team_nickname,
    sch.home_team_abbrev,
    sch.away_team_id_1032,
    sch.away_team_id,
    sch.away_team_name,
    sch.away_team_nickname,
    sch.away_team_abbrev,
    opt.possession,
    rank () over (order by possession desc) as rankings_order
    from 
    customer_data.cd_soccer_schedule sch,
    soccer.soccer_optical_team_gm_stats opt
    where    sch.game_code = opt.game_code
    and      sch.season_id = 200921
    and      opt.possession is not null
    order by rankings_order asc
    )It outputs the following (Sorry for it being so cramped together):
    **Note: Columns are in the same order as the query, I didn't post the column names b/c everything would look even sloppier then it doesAre you sure?
    The 6th column in the query is home_team name; the 6th column of the output has values like 5359 and 5354. Did you perhaps duplicate the rankings_iorder column at the beginning of the results?
    Why don't you simplify the problem. Instead of 15 or 16 columns, 10 of which are twins (5 pairs of 2 columns), why don't you post a problem with 6 columns, 4 of which are twins? Pick short columns, such as home_team_abbrev rather than home_team_name.
    Adding the other columns later should be easy; merely a matter of coping one of the columns ion the solution.
    Whenever you have a problem, post some sample data and the results you want from that data.
    In this case, the sample data can be about 6 columns from the result set below. I'll bet you can make a good sample set with fewer than 12 rows, also.
    1     5358     870986     2009050606     6     5359     Kansas City     Wizards     KC     5     5358     D.C.     United     DC     69.5%     1
    2     5354     870945     2009040501     1     5354     Chicago     Fire     Chi     10     5362     New York     Red Bulls     RB     58.1%     2
    3     5721     870983     2009050211     11     5363     San Jose     Earthquakes     SJ     17     5721     Chivas USA          Chv     56%     3
    4     5360     870984     2009050207     7     5360     Los Angeles     Galaxy     LA     10     5362     New York     Red Bulls     RB     55.6%     4
    5     5361     870961     2009041705     5     5358     D.C.     United     DC     9     5361     New England     Revolution     NE     55.4%     5
    6     5362     870988     2009050810     10     5362     New York     Red Bulls     RB     11     5363     San Jose     Earthquakes     SJ     50.1%     6
    7     5363     870988     2009050810     10     5362     New York     Red Bulls     RB     11     5363     San Jose     Earthquakes     SJ     49.9%     7
    8     5358     870961     2009041705     5     5358     D.C.     United     DC     9     5361     New England     Revolution     NE     44.6%     8
    9     5362     870984     2009050207     7     5360     Los Angeles     Galaxy     LA     10     5362     New York     Red Bulls     RB     44.4%     9
    10     5363     870983     2009050211     11     5363     San Jose     Earthquakes     SJ     17     5721     Chivas USA          Chv     44%     10
    11     5362     870945     2009040501     1     5354     Chicago     Fire     Chi     10     5362     New York     Red Bulls     RB     41.9%     11
    12     5359     870986     2009050606     6     5359     Kansas City     Wizards     KC     5     5358     D.C.     United     DC     30.5%     12What i'm trying to do is basically have the output formated so that when the team_id column matches the either the home_team_id or away_team_id colum i want the following columns to be renamed as:
    so if team_id = home_team_id for example then I want the following...
    sch.home_team_id_1032 as team_code_1032,
    sch.home_team_id as team_code,
    sch.home_team_name as team_name,
    sch.home_team_nickname as team_nickname,
    sch.home_team_abbrev as team_abbrev
    and then the away team columns would be...
    sch.away_team_id_1032 as opp_team_code_1032,
    sch.away_team_id as opp_team_code,
    sch.away_team_name as opp_team_name,
    sch.away_team_nickname as opp_team_nickname,
    sch.away_team_abbrev as opp_team_abbrev
    and same thing vice versa if the team_id column matches the away_team_idSorry, column names have to stay the same throughout the query. This is a very unusual request, and it's hard for me to imagine what you really want.
    You miight be able to do a UNION and add rows that look like column headings.
    No kidding, you have to post the results you want.
    No matter how clear an idea you have of what those resutls should be, no one else knows, and it's much easier to post the correct results than to accurately describe them.

  • Which info object should be used for Financial statement line (BPS and BCS)

    Hi experts.
    A rather easy and straightfoward questions for someone out there.
    In BPS as we know, we use the info object '0SEM_POSIT' (account groups, or financial statement line) to summamrize and store amounts from groups of accounts or for example data from COPA's value fields, and which is already an attribute of the info object '0ACCOUNT'.
    I am told that there is another BCS related info object called '0CS_ITEM' that serves the same purpose, and uses it for the same reason for the purpose of consolidations.
    We'd obviously like to use just the one of these info objects because of planning and reporting.
    Can someone out there with knowledge in BCS recommend which one to use, and from their experience in the past how they combined the use of both (if you in fact did use both).
    Also, is it true that in BCS you cannot use a two characteristic BW hierarchy for consolidations, and it can only consolidate a one characteristic BW hierarchy?
    Thanks dearly

    Hi Eugene,
    I kind of understood what you said, but just incase, let me explain my situation a little clearer. In BPS I'm using 0SEM_POSIT for two reasons:
    1) To create hierarchy based on 0SEM_POSIT info object, and making each node postable. This is because on this project we don't plan at account level. Only at a kind of account group/financial statement line level. So each node is postable so that they roll up to the higher levels.
    2) I will have 0SEM_POSIT as an attribute of 0ACCOUNT (which is standard delivered as an attribute in BW). This will ensure that I derive the actuals at that the same level as the planned. This is required for two reasons:
                               a) I can have the actuals as comaprison column in the Planning
                                   layout.
                               b) I can report on the Actuals vs. Plan at the postable node
                                   level in BW queries.
    So having explained this, what I understood from your explanation is:
    a) I can continue to 0SEM_POSIT as my info object for my postable node hierarchy, and
    b) I can also use 0CS_ITEM as a consolidation unit specifically for BCS only.
    So what I really didn't understand is:
    1) your explanation of the mapping of 0SEM_POSIT to 0CS_ITEM, and what this mapping actually does. For example does 0CS_ITEM derive the values from 0SEM_POSIT because of this mapping? Can you explain this a bit? Is Datastream a tool in BCS by which BCS readinf financial data from other components?
    2) Can BCS use a 2 characteristic postable nodes hierarchy as a consolidation unit? For example, if I create ONE hierarchy using 0SEM_POSIT, and 0ACCOUNT. Both will be postable at any level of the hirarchy.
    Can BCS consolidate using this 2 characteristic hierarchy structure? OR, must it use 0CS_ITEM info object?
    3) How does both 0SEM-POSIT, and 0CS_ITEM co-exist together, in terms of planning, consolidation, and reporting. For example if I report using the 0CS_ITEM hierarchy, then I will not be able to read plan data, because plan data is posted on the 0SEM_POSIT? and vice versa......? This question kind of ties in with 1).
    Sorry for the long message, but I wanted to make sure I explained it better.
    Thanks for your help

  • Errors when using the Call statement for MS SQL Server

    I've tried executing a Stored Procedure using the Call method of Portal 2 Go. But it gets an internal error b/c of it. Any Ideas why and how to resolve?

    Hello,
    Which version of SAP BOBJ XI3.1 you are using?
    What I am aware is BEGIN_SQL was very well working for SQLServer2005 in case of ODBC connection.
    Can you try one thing for SQLServer2008 have a Native driver installed on your client machine and use ODBC connection rather than OLEDB connection.
    If that works fine, its good
    Otherwise you can raise a message for resolving this problem with the support team.
    Thanks,
    Vivek

Maybe you are looking for

  • JVM Tuning in SOA 10.1.3.4

    Hi experts, Thanks for the information. We are currently facing issue. The description is as follows: 1. We are having a SOA cluster with version 10.1.3.4 and facing high memory utilization on both the application nodes. 2. We have observed that the

  • Year to date calculations

    Hi All, I am using Planning V11 I wanted to display YTD data on webforms. Now the data is loaded at the month level and there is a requirement to see the values for YTD aswell. I wanted to know the best practices around calculating YTD data in planni

  • Oracle JDBC ArrayOutOfBoundsException

    I keep getting an ArrayOutOfBounds exception when calling resultSet.updateRow() after modifying the resultset. The stacktrace is as follows.      Nested exception is: java.lang.ArrayIndexOutOfBoundsException: 8      at oracle.jdbc.driver.OracleSql.co

  • What happened to the code reference panel from CS5?

    I have been watching a CS5 Flash ActionScript tutorial, but I am using Flash CC. In the tutorial, there is a code reference panel to the left of the actions panel that has a list of all the possible code pieces, and when hovering over any of them, it

  • D800E raw files on import

    Trying to import D800E raw files from a CF into Lightroom 4, "no photos found" is the message.  Images can be seen in camera so I know they are there.  LR version is up to date. Raw Plug-In version is up to date.  I can import D4 raw files from CF so