MySQL Select Statement Help Required

I am trying to generate a report in VS 2008 (C#) using a mysql select statement but cannot get it right.
I have groups that meet on a weekly basis on different days. I want to generate a report that shows me all the members that have not attended their group where they have missed 3 meetings in a row.
Below is the select statement I have tried but it does not give me the results I am looking for. I have tried to look at all the meetings in a 4 week period but would prefer to look at the last 3 meetings that are recorded. Some groups might not record a meeting every week. So I want to look at the last 3 recorded meetings and count each members attendance and only report on the members with more than 3 meetings missed.
SELECT COUNT(`groupattendance`.`Attended`) AS Attendance, `smallgroupform`.`MeetingDate`, `userinfo`.`FirstName`, `userinfo`.`Surname`, `smallgroup`.`GroupName`, `groupattendance`.`Attended`, `groupattendance`.`UserID`, `groupattendance`.`GroupID`
FROM ((`anatomy`.`groupattendance` `groupattendance`
INNER JOIN `anatomy`.`smallgroupform` `smallgroupform` ON `groupattendance`.`FormID` = `smallgroupform`.`FormID`)
INNER JOIN `anatomy`.`userinfo` `userinfo` ON `groupattendance`.`UserID` = `userinfo`.`UserID`)
INNER JOIN `anatomy`.`smallgroup` `smallgroup` ON `groupattendance`.`GroupID` = `smallgroup`.`GroupID`
WHERE (`smallgroupform`.`MeetingDate` >= DATE_SUB(CURDATE(),INTERVAL 4 WEEK) AND `smallgroupform`.`MeetingDate` <= CURDATE()) AND `groupattendance`.`Attended` = 'False'
GROUP BY `userinfo`.`UserID`
HAVING Attendance >= 3
Thanks,
Garth.

Hi Garth,
Seems no one can help you directly. Try googling your SQL request. Someone may be able to help you. At this point its not really a Cr problem.
One option is to get all the data and add filtering using the record selection formula.
Thank you
Don

Similar Messages

  • Conditional Mysql select statement

    HI Folks
    can anyone point me in the right direction with a MySQL statement.
    I will try to layout my thinking here:
    I have a form with three inputs area, name and search. I am trying to write a Mysql select statement that selects records from a single table if they match the criteria. Easy for two variables but I'm lost after that.
    1. The form includes these three inputs:
    area - drop down menu (Any as default)
    name - drop down menu (Any as default)
    search box - text area (Blank as default)
    2. The form submits to itself leaving me with these three variables
    $search=$_GET['search']
    $area=$_GET['area']
    $name=$_GET['area']
    SELECT * FROM database WHERE database.description LIKE '%$search%' AND database.area LIKE '$area' AND database.name LIKE '$name'
    3. This is where I get confused. How do I get the SQL to Select everything correctly. I have tried using PHP if/else code to fix it but I end up running around in circles with six different Select statements and haven't yet got that to work.
    So I have come to the conclusion that there must be an easier way.  I see search forms with dozens of  search criteria on websites every day an d I only have 3 - so it can't be this complicated. Right?
    I know I need to start from the beginning again but can anyone let me know how to approach it before I begin?
    Cheers
    Dave

    Typically, I would build the where clause dynamically, based upon the values in your form. If the form field contains 'Any', leave it out of the where clause. So you can test each field value and either append or not to the end of the where clause.

  • Concat java variable to a MySql select statement and exeucte

    Hi,
    I am trying to append a variable to a MySql select statement.
    Overview: I need to retrieve data from a MySql database with a java variable as a reference and select the data in the database based on that variable.
    CODE THAT I CURRENTLY HAVE:
    // Declare variables
    Connection conn = null;
    Statement st = null;
    Resultset rs2 = null;
    String st2 = null;
    String keyid = null;
    // Connect to database
    try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
          st = conn.createStatement();
          // Select data in Database with hanging equal sign
          st2 = ("SELECT * FROM table WHERE keyid= ");
          // Append keyid to hanging equal sign of select statement
          rs2 = st.executeQuery(st2 + keyid);
    }This is not working when I try to display the data.

    What is not working about it? Is there an error message? Stack Trace?
    Where do you get the value of keyId from?
    I would suggest that you use a prepared statement rather than building up a sql string like this. It prevents sql injection attacks
    // Declare variables
    Connection conn = null;
    PreparedStatement stmt = null;
    Resultset rs2 = null;
    String sql= null;
    String keyid = null;
    // Connect to database
    try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
          // Select data in Database with place holder for parameter
          sql = "SELECT * FROM table WHERE keyid= ?";
           // prepare the statement
          stmt = conn.prepareStatement(sql);
          // set the value of key id to use with the query
          stmt.setString(1, keyId);
          // run the query
          rs2 = st.executeQuery();
    catch (Exception e){
      System.out.println("An error occurred " + e.getMessage());
      e.printStackTrace();
    finally{
      if (rs2 != null) try { rs2.close(); } catch(SQLException ex){}
      if (stmt != null) try { stmt.close(); } catch(SQLException ex){}
      if (conn != null) try { con.close(); } catch(SQLException ex){}
    }

  • MySql select statement in jsp page

    Ok,
    I need help with this select statement.
    <%
    // Determine what option is set to.
    if(option == null || "".equals(option) || "Verify1".equals(option)){
      if("Verify1".equals(option)){
      // Retrive query specific to submitted form.
      try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
          st = conn.createStatement();
          rs= st.executeQuery("SELECT organization FROM tblevent_approval WHERE MAX (keyid))";
          // Get query results.
          while(rs.next()){
            organization = rs.getString("organization");
      finally {
            if(rs != null){
              rs.close();
            if(st != null){
              st.close()
            if(conn != null){
              conn.close();
    %>THE ERROR I AM GETTING
    Syntax error, insert ")" to complete Expression

    This line has the closing bracket inside the closing quote for the statement...
    >       rs= st.executeQuery("SELECT organization FROM tblevent_approval WHERE MAX (keyid))";It should be:
    rs= st.executeQuery("SELECT organization FROM tblevent_approval WHERE MAX (keyid)");A simple typo ;-)
    Hope this helps...

  • Mysql select statement where = works and LIKE fails

    I am using Flash Builder 4. On the server side I use php and mysql. I created a php dataservice using FB4. My plan had been to allow users to enter a search term and query the database using a "LIKE" statement. FB4 created the php code that I simply modified changing the parameter name. The input parameter is a string.
    public function getT_caseByID($searchTerm) {
    $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename WHERE (title = ?)");
    $this->throwExceptionOnError();
    mysqli_stmt_bind_param($stmt, 'i', $searchTerm);
    $this->throwExceptionOnError();
    mysqli_stmt_execute($stmt);
    $this->throwExceptionOnError();
    mysqli_stmt_bind_result($stmt, $row->idt_case, $row->title, $row->id_author, $row->comments);
    if(mysqli_stmt_fetch($stmt)) {
          return $row;
    } else {
          return null;
    A look at FB4 shows this code returns data.
    This code works fine but if I make the below change it fails, even when I use the wildcard %. the only change is "=" to "LIKE".
    public function getT_caseByID($searchTerm) {
    $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename WHERE (title LIKE ?)");
    $this->throwExceptionOnError();
    mysqli_stmt_bind_param($stmt, 'i', $searchTerm);
    $this->throwExceptionOnError();
    mysqli_stmt_execute($stmt);
    $this->throwExceptionOnError();
    mysqli_stmt_bind_result($stmt, $row->idt_case, $row->title, $row->id_author, $row->comments);
    if(mysqli_stmt_fetch($stmt)) {
         return $row;
    } else {
         return null;
    A look into FB4 shows "void".
    Any help would be appreciated. I am using localhost on Apache Server on a development computer with Windows XP.

    correctio0n on the select statement
    select statement code*********
    select
        apspnr astspr aobjnr apspid
        bpsphi bposid
        caufnr cpspel
        dinact dstat
        eudate eusnam eutime "estat
       F~TXT04
        g~estat
        G~TXT04
        into corresponding fields of table itobj
        from proj as a
        inner join prps as b on apspnr = bpsphi
        inner join aufk as c on bpspnr = cpspel
        inner join jest as d on cobjnr = dobjnr
        inner join jcds as e on dobjnr = eobjnr
                             and dstat = estat
        inner join tj02t as f on estat = fistat
        inner join tj30t as g on astspr = gstsma
        for all entries in itparm
        where  apspid = itparm-pspid "or estat = itparm-psy )
        or  bposid = itparm-posid "or estat = itparm-wsy )
        or  caufnr = itparm-aufnr "or estat = itparm-nsy  )
        and ( dinact  'X' or einact  'X')
        and fspras = 'E' and gspras = 'E'.

  • Selection Screen - Help required

    Hi ,
    I am developing a SD report in which he selection screen is executed without any inputs it shows me the customers which are maintained against my ID in a Ztable.
    However customer needs for internal users he should be able to view all without any inputs.
    can anyone help me..?
    Varun

    hi Varun,
    do not include the user id on the where condition on your select statement.
    regards,
    Peter

  • MySql select statement

    Hi All,
    I have java application which suppose to connect to MySql server and print the selected data.
    The application has 4 combo boxes (first item is empty): Name, Customer, Supplier, Status.
    User could choose any of these options. So there are huge number of select combinations.
    Is it possible to create one select statement template something like this:
    PreparedStatement stmt = con.prepareStatement( "SELECT * from database WHERE user_id = ?,
    and customer_id = ?,
    and supplier_id = ?,
    and status = ? " );
    if ( ! ComboBox.getSelectedItem().toString().isEmpty() )
    stmt00.setString( 1, ComboBox.getSelectedItem().toString() );
    else
    stmt00.setString( 1, "*" );
    etc…
    I'm stuck at this part stmt00.setString( 1, "*" ). Is there any way to write statement SELECT * from table WHERE column = * ?
    What is the proper way to write such selection ?
    Thanks in advance,
    Vladimir

    Is there any way to write statement SELECT * from table WHERE column = * ?No, that's invalid SQL.
    What is the proper way to write such selection ?If you need in one case to select a single user, but in another case to select all of them, then you need to handle two different SQL statements.
    1. SELECT * from table WHERE column = value
    2. SELECT * from table
    This has nothing to do with Java.

  • SQL select statement help

    Say i have a table that has the following fields...
    ID    field1    field2   field3  field4   field5   field6   field7
     1        1           2         E         NW     SW  
         n         n
     2        1           2         E         NE      SW  
         n          n 
     3        1           3         W        NE      SE  
          n          n 
    10,000 plus entries in this table:  it is state quarter quarter data if it helps... 
    So i was handed a list on paper that has about 500 of these quarters from the above said table but there is no ID. I am having a someone build an excel spread
    sheet in the fashion above but the only fields will be as follows
    ID(NOT THE SAME AS ABOVE)  field1   field2  field3 field4  field5
    1                                                  
    1           1         W      NW    NE
     500 or so entries in this table
    no field 6 or 7
    how would i go about selecting all the fields from the top table that match exactly fields 1-5 in the excel sheet?
    and no there are no duplicate entries in the top table.
    thanks,
    james
    dogdaynoon

    Is field6 and field7 nullable fields in yourtable?
    If yes you can simply ignore them in your insert statements
    If you're directly dumping the contents of excel to table then it would be like
    INSERT YourTable (field1,field2,field3,field4,field5)
    SELECT field1,field2,field3,field4,field5
    FROM OPENROWSET(....) AS f
    if you're populating a tsgaing table you can do like this
    INSERT YourTable (field1,field2,field3,field4,field5)
    SELECT field1,field2,field3,field4,field5
    FROM StagingTable s
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Attendance Report Select Statement Help

    Hello , 
    i am working on the a Report for Attendance , for each employee , i want to show the report for a Date Range , i want to show 
    all days even if he is absent , the table structure for getting the attendance is just one Table , where i take the min time and max time for the employee 
    i want to show it as the below : 
    Date    Time In     Time Out 
    1-1     7:45            16:00 
    1-2     7:05            16:48 
    1-3     Null      Null 
    1-4     8:00            14:00 
    i have created a table TCalendar with all Dates and want to join it with the Transactions Table 
    Select UserID ,FirstName + ' ' + LastName as [Employee Name],  Convert(Varchar,min(OccurDateTime),108) as MinDate, Convert(Varchar,max(OccurDateTime),108) as maxDate
      , Department , Rank , Cast(ISNull(Datediff(mi,min(OccurDateTime),max(OccurDateTime)),'') as Decimal(4,0)) / 60 as [Total Hours] , DATENAME(DW,max(OccurDateTime))+ ' ' +  CONVERT(varchar, Record_Day, 106) as Date
    from
      TTransactionLog1 T Full Outer Join TCalendar C On C.Record_Day = T.OccurDateTime
      where OccurDateTime between '2015-01-01' and '2015-01-06' and UserID <> '' and UserID = 'AKHG1030'
    group by CONVERT(varchar, OccurDateTime, 106), UserID , FirstName , LastName , Department , Rank 
    The Results currently show like this 
    UserID Employee Name
    MinDate maxDate
            Total Hours
    Date
    AKHG1030 Osama Ashraf
    07:44:37 12:27:07
    4.716666
    NULL
    AKHG1030 Osama Ashraf
    11:08:18 15:49:12
    4.683333
    NULL
    AKHG1030 Osama Ashraf
    07:43:00 15:31:30
    7.800000
    NULL
    AKHG1030 Osama Ashraf
    07:27:35 18:56:22
    11.483333
    NUL
    need your Help 

    I think this is what you're aiming for:
    DECLARE @transactions TABLE (ID INT IDENTITY, empID INT, datetime DATETIME)
    INSERT INTO @transactions (empID, datetime)
    VALUES (1, '2015-01-01 07:44:37'),(1, '2015-01-01 12:27:07'),(1, '2015-01-02 11:08:18'),(1, '2015-01-02 15:49:12'),(1, '2015-01-03 07:43:00'),(1, '2015-01-03 15:31:30'),(1, '2015-01-05 07:27:35'),(1, '2015-01-05 18:56:22')
    DECLARE @employees TABLE (ID INT, firstName VARCHAR(30), lastName VARCHAR(30), userID VARCHAR(8))
    INSERT INTO @employees (ID, firstName, lastName, userID)
    VALUES (1, 'Osama', 'Ashraf', 'AKHG1030')
    SELECT c.today, e.ID, MIN(datetime) AS inTime, MAX(datetime) AS outTime, DATEDIFF(MINUTE,MIN(datetime),MAX(datetime))/60.0 AS hours
    FROM toolbox.dbo.calendar c
    FULL JOIN @employees e
    on e.id = e.id
    LEFT OUTER JOIN @transactions t
    ON c.today = CAST(t.datetime AS DATE)
    WHERE c.today BETWEEN '2015-01-01' AND '2015-01-05'
    GROUP BY c.today, e.ID
    ORDER BY c.today
    I created mock ups of a transactions table which holds the transactions data, and an employee ID column and an employee table which holds employee data.
    I am using my calendar table/functions which you can read about here:
    http://social.technet.microsoft.com/wiki/contents/articles/29260.tsql-calendar-functions-and-tables.aspx.
    We full joined the employee table (creating a cartesian product between the date and all employees) so we always show every employee for every date. Then, we left outer join the transaction table to find the records for that date. We aggregate the min and
    max, and use them in a date add to find the total number of hours between them. I'ved used minutes and devided by 60.0 (to force the decimal) to give partial hours.
    hth.

  • Select statement help

    I need somebody to look at this statement for me.  I can't figure out why it is giving me a syntax error:
    DATA: meg001 LIKE coss-meg001,
          meg002 LIKE coss-meg002,
          meg003 LIKE coss-meg003,
          meg004 LIKE coss-meg004,
          meg005 LIKE coss-meg005,
          meg006 LIKE coss-meg006,
          meg007 LIKE coss-meg007,
          meg008 LIKE coss-meg008,
          meg009 LIKE coss-meg009,
          meg010 LIKE coss-meg010,
          meg011 LIKE coss-meg011,
          meg012 LIKE coss-meg012.
        SELECT SINGLE meg001 meg002 meg003 meg004 meg005 meg006 meg007 meg008 meg009 meg010 meg011 meg012
                INTO (d_meg001, d_meg002, d_meg003, d_meg004, d_meg005, d_meg006, d_meg007, d_meg008, d_meg009, d_meg010, d_meg011, d_meg012)
                FROM coss WHERE objnr = wa_table-objnr.
    Regards,
    Aaron

    Where did you declare d_meg001?
    it should be into (meg001 , meg002....)
    DATA: meg001 LIKE coss-meg001,
          meg002 LIKE coss-meg002,
          meg003 LIKE coss-meg003,
          meg004 LIKE coss-meg004,
          meg005 LIKE coss-meg005,
          meg006 LIKE coss-meg006,
          meg007 LIKE coss-meg007,
          meg008 LIKE coss-meg008,
          meg009 LIKE coss-meg009,
          meg010 LIKE coss-meg010,
          meg011 LIKE coss-meg011,
          meg012 LIKE coss-meg012.
    data: v_objnr type coss-objnr.
        SELECT SINGLE meg001 meg002 meg003 meg004 meg005 meg006 meg007 meg008 meg009 meg010 meg011 meg012
                INTO (meg001, meg002, meg003, meg004, meg005, meg006, meg007, meg008, meg009, meg010, meg011, meg012)
                FROM coss WHERE objnr = v_objnr.

  • Simplify the query/select statement help

    select distinct B_Billing_key, B_COMPANY_ID "Company" ,
    to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
    trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') "Billing Period",
    (nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))"Period_Balance",
    decode(sign((nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))),1, 'Yes'
    ,'No'
    )"outstanding_balance"
    p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR "Programname"
    FROM tuff_balance_view,MV_PROG_SURCH S,MV_PAYMENT_HOLDING H,MV_PROGRAM_DICT P where
    b_company_id = 'XYZ'
    and B_Billing_key=s.BILLING_KEY
    and S.PROGRAM_KEY = P.PROGRAM_KEY
    and P.PROGRAM_KEY= H.PROGRAM_KEY
    GROUP BY B_Billing_key,B_COMPANY_ID,B_REPORT_PERIOD,SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,PROG_SURCH_KEY,
    S.PROGRAM_KEY,p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR,AMOUNT
    order by B_Billing_key desc
    B_Billing_key is the primary key. I am looking for the output only one record for each biling perid. there are 2 programs for each billing period. if any of the program has period balance >0 then outstanding balance should be yes.
    The output from the above query is as below.
    biling_key company billing period period_balance outstandingbalance programname
    123 xyz January 2011 4 Yes ABC
    123 xyz January 2011 -5 NO DEF
    456 xyz February 2011 -3.0 No ABC
    456 xyz February 2011 2 Yes DEF
    Need the output as below from the above query. Can you please help to simplify query. If anyof theprogram having outstanding balance for that particular period show the outstandigbalance as yes. Else NO.
         company billing period outstandingbalance programname
    xyz January 2011 Yes ABC
    xyz February 2011 Yes DEF
    Thanks,
    vi

    <font face="courier">
    <font color="green">-- this just simulates the results of your original query - meant just to play with until everything works</font>
    <br>
    with
    your_query as
    (select 123 billing_key,'xyz' company,'Jan 2011' billing_period,'No' outstandingbalance,'ABC' programname from dual union all
     select 123,'xyz','Jan 2011','Yes','DEF' programname from dual union all
     select 123,'xyz','Jan 2011','No','GHI' programname from dual union all
    <font color="green">--comment out some data row to see what happens when having just 5 programs
    --</font> select 123,'xyz','Jan 2011','No','JKL' programname from dual union all
     select 123,'xyz','Jan 2011','Yes','MNO' programname from dual union all
     select 123,'xyz','Jan 2011','No','PQR' programname from dual union all
     select 456,'xyz','Feb 2011','No','ABC' programname from dual union all
     select 456,'xyz','Feb 2011','No','DEF' programname from dual union all
     select 456,'xyz','Feb 2011','No','GHI' programname from dual union all
     select 456,'xyz','Feb 2011','No','JKL' programname from dual union all
     select 456,'xyz','Feb 2011','No','MNO' programname from dual union all
     select 456,'xyz','Feb 2011','No','PQR' programname from dual
    <font color="green">-- end of generated data
    -- the "real" query follows
    </font>
    <br>
    <font color="blue">
    select billing_key,
           company,
           billing_period,
           case when programname = ',,,,,' then 'No' else 'Yes' end outstandingbalance,
           case when programname != ',,,,,'
                then trim(',' from replace(replace(replace(programname,',',',~'),'~,'),'~'))
           end programname
      from (select billing_key,company,billing_period,'Yes' outstandingbalance,
                   max(case when outstandingbalance = 'Yes' and programname = 'ABC' then 'ABC' end) || ',' ||
                   max(case when outstandingbalance = 'Yes' and programname = 'DEF' then 'DEF' end) || ',' ||
                   max(case when outstandingbalance = 'Yes' and programname = 'GHI' then 'GHI' end) || ',' ||
                   max(case when outstandingbalance = 'Yes' and programname = 'JKL' then 'JKL' end) || ',' ||
                   max(case when outstandingbalance = 'Yes' and programname = 'MNO' then 'MNO' end) || ',' ||
                   max(case when outstandingbalance = 'Yes' and programname = 'PQR' then 'PQR' end) programname
              from (
                     <font color="green">--your_query here</font><br>
    <font color="red">
                    select distinct B_Billing_key, B_COMPANY_ID "Company" ,
                    to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
                    trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') "Billing Period",
                    (nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))"Period_Balance",
                    decode(sign((nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))),1, 'Yes'
                    ,'No'
                    )"outstanding_balance"
                    p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR "Programname"
                    FROM tuff_balance_view,MV_PROG_SURCH S,MV_PAYMENT_HOLDING H,MV_PROGRAM_DICT P where
                    b_company_id = 'XYZ'
                    and B_Billing_key=s.BILLING_KEY
                    and S.PROGRAM_KEY = P.PROGRAM_KEY
                    and P.PROGRAM_KEY= H.PROGRAM_KEY
                    GROUP BY B_Billing_key,B_COMPANY_ID,B_REPORT_PERIOD,SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,PROG_SURCH_KEY,
                    S.PROGRAM_KEY,p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR,AMOUNT
                    order by B_Billing_key desc
    </font>
             group by billing_key,company,billing_period
    </font>
    </font>
    Regards
    Etbin
    your simplified query should look somehow like below
    you didn't provide table structures and sample data so:
    aliases were assigned arbitrarily
    using sum(nvl(s.SURCH_AMOUNT,0) + nvl(s.ADJUST_AMOUNT,0) + nvl(s.PI_AMOUNT,0) - nvl(v.AMOUNT,0)) is most certainly wrong
    select v.B_Billing_key,
           v.B_COMPANY_ID company,
           to_char(to_date(substr(v.B_REPORT_PERIOD,1,6),'yyyymm'),'Month yyyy') billing_period
           case when sum(nvl(s.SURCH_AMOUNT,0) + nvl(s.ADJUST_AMOUNT,0) + nvl(s.PI_AMOUNT,0) - nvl(v.AMOUNT,0)) > 0
                then 'Yes'
                else 'No'
           end outstandingbalance,
           p.PROGRAM_NAME_ID programname
      FROM tuff_balance_view v,
           MV_PROG_SURCH S,
           MV_PAYMENT_HOLDING H,
           MV_PROGRAM_DICT P
    where v.B_COMPANY_ID = 'U-7052-C'
       and v.B_Billing_key = s.BILLING_KEY
       and S.PROGRAM_KEY = P.PROGRAM_KEY
       and P.PROGRAM_KEY = H.PROGRAM_KEY
    group by B_Billing_key,
              B_COMPANY_ID,
              to_char(to_date(substr(B_REPORT_PERIOD,1,6),'yyyymm'),'Month yyyy'),
              p.PROGRAM_NAME_IDEdited by: Etbin on 2.3.2011 22:44

  • Report Select Statement Help

    I need some help with creating a report.
    I have a table with two columns
    (ROOM number, NAME varchar2(15))
    I need to create a report that identifies each room and on the same line all the people that are in that room.
    It needs to looks like this:
    room Name
    101 Smith,Jones,Roberts,Flores,Larson,etc
    Thanks in advance for any help,
    Kirk

    There are a few ways to do this. Just write a function with a cursor and in the loop , create the output string.
    There is some info to do this in asktom which you can search to find the answer

  • Selection screen Help required urgently?

    Hi experts,
    I need to gve a popup on slection. This popup will contain table with col1 and col2.
    The user needs to enter data in this..
    I tried using table control, but I am not able to handle it properly..
    Can you please help me with a sample code of report similiar to above..
    Its urgent

    data : itabt like sval occurs 0 with header line.
    itabt-tabname = 'MARA'.
    itabt-fieldname = 'MATNR'.
    append itabt.
    itabt-tabname = 'MARD'.
    itabt-fieldname = 'LGORT'.
    append itabt.
    CALL FUNCTION 'POPUP_GET_VALUES'
      EXPORTING
      NO_VALUE_CHECK        = ' '
        POPUP_TITLE           = 'Enter value'
       START_COLUMN          = '5'
       START_ROW             = '5'
    IMPORTING
      RETURNCODE            =
      TABLES
        FIELDS                = itabt
    EXCEPTIONS
      ERROR_IN_FIELDS       = 1
      OTHERS                = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    you can use return code also.
    regards
    shiba dutta

  • Select statement help for sql/oracle newbie

    I have a db for a fake airline. i have a route table that has columns for "FIRST_CLASS_FARE", "COACH_FARE", and "ECONOMY_FARE". I then have a flight table that references the route#, then a trip table that references the flight#. I also have a passenger table and a reservation table that has the passenger # in it. The reservation table also has a column called "reservation class" that has a 'f' for first class fare, 'c' for coach fare, 'e' for economy fare.
    What I am trying to do is create a fill for each individual passenger that shows the total amount they spent on all of their reservations.
    Any suggestions on how to join the tables to create this bill?
    Thanks in advance!

    Is it the way the passenger table has columns and is populated,
    for a passenger A, takes a route - 1 with First class fare - $2500 on flight- B123, to a trip - t1 and reserved for class - 'f'
    If this is the way, then you get the bill from the fare column

  • Urgent help on difficult programming  required -remove select statement

    loop at zt_wbs.
      clear   zt_cobrb.
      refresh zt_cobrb.
    Select settlement rules
      select distinct anln1 anln2 from cobrb
             into corresponding fields of table zt_cobrb
             where objnr = zt_wbs-objnr and
                   perbz = 'GES'        and
                   konty = 'AN'.
        if sy-subrc = 0.
          describe table zt_cobrb lines i.
          if i = 1.
        unique settlement rule
            read table zt_cobrb index 1.
            zt_changes-equnr = zt_wbs-equnr.
            zt_changes-anln1 = zt_cobrb-anln1.
            zt_changes-anln2 = zt_cobrb-anln2.
            collect zt_changes.
          endif.
        endif.
    endloop.
    hii...i can modify the structure of table zt_cobrb  if required. please tell me a code in which i can carry my select statements outside the loop.and do the same thing.
    remember there is a distinct keyword after select statement and i have to loop at zt_wbs having one of the fields objnr.

    loop at zt_wbs.
      clear   zt_cobrb.
      refresh zt_cobrb.
    Select settlement rules
      select distinct anln1 anln2 from cobrb
             into corresponding fields of table zt_cobrb
             where objnr = zt_wbs-objnr and
                   perbz = 'GES'        and
                   konty = 'AN'.
        if sy-subrc = 0.
          describe table zt_cobrb lines i.
          if i = 1.
        unique settlement rule
            read table zt_cobrb index 1.
            zt_changes-equnr = zt_wbs-equnr.
            zt_changes-anln1 = zt_cobrb-anln1.
            zt_changes-anln2 = zt_cobrb-anln2.
            collect zt_changes.
          endif.
        endif.
    endloop.
    hii...i can modify the structure of table zt_cobrb  if required. please tell me a code in which i can carry my select statements outside the loop.and do the same thing.
    remember there is a distinct keyword after select statement and i have to loop at zt_wbs having one of the fields objnr.

Maybe you are looking for

  • Container Operation in BPM

    Hi, I have a BPM that should change a message with a container operation. The message got the structure: message |-errorcode is it possible to fill the errorcode (string) with a container operation? It is an abstract interface. Or is a container oper

  • Field values erases when Add Row button is pressed in Master Detail Form

    Hi, I am using APEX 4.0. There is a master-detail form in a page, this has 5 rows in it by default, has a Add row and a Delete button. I face two problems now: 1. When the values are entered in all the 5 rows, that are in default, and Add Row button

  • Special GL postings error

    Hi all, I am trying to post Advance payment posting in F-48. I selected special indicator: A and the error coming like ''''No special G/L acct defined for acct type K sp.G/L ind. A recon.acct 100502'' What is these special GLs and how they are relate

  • Iphoto is not able to load my pictures

    Hello I have a problem while running iphoto. The program is not able to load my pictures it gets stock searching for pictures and does not displays a single image, none of the commands respond Can you give an advice. How can I reinstall this program.

  • Where is the complete list of what does and doesn't get backed up on iOS?

    I found a webpage from Macworld pointing to Back up and restore your iPhone, iPad, or iPod touch using iCloud or iTunes - Apple Support as giving a complete list of what does and does not get backed up in the iPhone backup.  This page must have chang