Condtion based xml for each row of the table t-sql

Hello ,
i have below data.
create table #students
id int identity(1,1) primary key,
student_id int not null,
[s_m_cml] xml
insert into #students
student_id,
[s_m_xml]
values
101,
'<submarks><submark><subject>Arts</subject><marks>85</marks></submark><submark><subject>Science</subject><marks>95</marks></submark><submark><subject>maths</subject><marks>100</marks></submark></submarks>'
),(102,'<submarks><submark><subject>Arts</subject><marks>50</marks></submark><submark><subject>Science</subject><marks>75</marks></submark><submark><subject>maths</subject><marks>85</marks></submark></submarks>')
select * from #students
if all subjects- marks in s_m_xml marks > 80 then i select the row as promoted else as demoted. the exact output should look like below.
student_id [status]
101 promoted
102 demoted
what is the best way to achieve this using t-sql. Thanks in advance for any suggestions.

You dont need to parse out the values from xml for this
You can do the check inline
see illustration below
drop table #students
create table #students
id int identity(1,1) primary key,
student_id int not null,
[s_m_cml] xml
insert into #students
student_id,
[s_m_cml]
values
101,
'<submarks><submark><subject>Arts</subject><marks>85</marks></submark><submark><subject>Science</subject><marks>95</marks></submark><submark><subject>maths</subject><marks>100</marks></submark></submarks>'
),(102,'<submarks><submark><subject>Arts</subject><marks>50</marks></submark><submark><subject>Science</subject><marks>75</marks></submark><submark><subject>maths</subject><marks>85</marks></submark></submarks>')
,(104,'<submarks><submark><subject>Arts</subject><marks>92</marks></submark><submark><subject>Science</subject><marks>88</marks></submark><submark><subject>maths</subject><marks>98</marks></submark></submarks>')
select *,
case when [s_m_cml].exist('/submarks/submark[data(marks) < 80]')=1 then 'demoted' else 'promoted' end as status
from #students
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • Different values in a list box for each row of the table control...

    Dear Experts,
    Is it possible to populate different values for each row in a listbox inside a table control ?
    Example,
    Row 1 in the the table contains A, B & C
    Row 2 in the same table contains C, D & E
    If yes, How?
    yes i am using
      call function 'VRM_SET_VALUES'
        exporting
          id     = i_name
          values = i_list.
    Thank you .
    Message was edited by:
            Kokwei Wong
    Message was edited by:
            Kokwei Wong

    Hi Wong,
    this is code example for listbox
    TYPE-POOLS vrm .
    DATA: lt_vrm_values TYPE TABLE OF vrm_value.
    DATA: wa_vrm_values TYPE vrm_value.
    PARAMETER p_list AS LISTBOX VISIBLE LENGTH 10.
    INITIALIZATION.
      wa_vrm_values-key = 'Key1'.
      wa_vrm_values-text = 'Value1'.
      APPEND wa_vrm_values TO lt_vrm_values.
      wa_vrm_values-key = 'Key2'.
      wa_vrm_values-text = 'Value2'.
      APPEND wa_vrm_values TO lt_vrm_values.
      wa_vrm_values-key = 'Key3'.
      wa_vrm_values-text = 'Value3'.
      APPEND wa_vrm_values TO lt_vrm_values.
    AT SELECTION-SCREEN OUTPUT.
      CALL FUNCTION 'VRM_SET_VALUES'
           EXPORTING
                id              = 'P_LIST'
                values          = lt_vrm_values
           EXCEPTIONS
                id_illegal_name = 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.
    To fill it with data from DB, just do select in INITIALIZATION and put that values with same alghoritmus.
    Manas M.
    P.S.: This is very easy question, you should use search ...

  • How to add a comment for each row on the output of a report?

    I would like to add a comment (field) for each row on the output of report? This comment should to be saved as well. Is there a way i can do that?
    Regards,
    Ram

    Hi Dimitri,
    through the instead of trigger functionality i am able to update the view. This is view is based on different views which should be linked to a table (as you suggested) in which comments can be stored. Hower this table is empty and how to link this table with the view now? I face the following challenge.
    View consists the following columns, for example
    select name, sex, age from test_view
    name sex age
    John M 20
    Anton M 30
    Willy M 40
    shirley F 38
    sharon F 37
    The report has the following output, for example
    name     sex age
    John     M 20
    Anton     M 30
    Willy M 40
    Shirley F 38
    Sharon F 37
    Now i would like to add comment through a button.
    The report layout looks like
    name sex age
    John M 20 <add comment button>
    After submitting the <add comment button> you can enter text which deals with John
    text='John doesnot like me'
    Finally the report display the comment as well
    name sex age
    John M 20 'John doesnot like me' <update/delete comment button>
    Anton M 30 <add comment button>
    Willy M 40 <add comment button>
    Shirley F 38 <add comment button>
    Sharon F 37 <add comment button>
    After submitting the <update/delete button> you can change or delete the entered text.
    I hope this example clears things up.
    Regards,
    Ram

  • How to activate a different sub-report for each row in the data set as main report page breaks on each row of data in the main dataset

    I am going to try asking this same question a different way as I have yet to find a working solution to my problem.  I have a main report and then 8 sub reports.  My main report has one data set and returns one row of data per account number.  One
    of the fields in the main data set is called AccountProf.  My main report displays one page per Account number and then calls a different sub report based on that account's AccountProf value.  The sub reports take in the account number as a parameter
    and get multiple rows of data to display that accounts usage formatted differntly for each AccountProf (hence the 8 different sub report.  
    So far I can figure out how to do everything but setting the visibility property of each sub-reports when I have multiple accounts.  If I use the following expression for the visibility property on each sub report, it makes all the applicable sub report
    for all the accounts requested visible at once:
    =IIF(Fields!AccountProf.Value= "USE_PLUS_DMD",False,True)
    *The value in bold USE_PLUS_DMD  is different for each sub report.
    Here is a look at what the main report look like:
    Here is the main reports data set:

    Hi JasonDWilson77,
    According to your description, there is a main report and 8 sub reports in the report, you want to set visibility of sub reports, if no value is passed to the parameter of sub report, the sub report will not be displayed. If that is the case, please refer
    to the following steps:
      1. Create a new parameter named NewAccountNumber, set its data type the same as @AccountNumber, select Allow multiple values, set Visibility to be hidden, then set all available values to default values.
      2. Right-click the first sub report and open Subreport Properties dialog box, click Parameters in left pane, set name to AccountNumber, then click (fx) button, type the expression like below:
    =Parameters! NewAccountNumber(0)
      3. Click Visibility in left pane, select Show or hide based on an expression, then click (fx) button and type the expression like below:
    =IIF(InStr(Join(Parameters! AccountNumber.Value), Parameters!NewAccountNumber.Value(0))>0 , false,true)
      4. Modify parameter of other sub reports like step2.
      5. Set visibility of other sub reports like step3.
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    If you have any feedback on our support, please click
    here.
    Wendy Fu
    TechNet Community Support

  • Prompting user for input for each row in the report

    Is it possible to have a user entered field for each row in a report ?
    ie. have a report with empolyee number, employee name, title, salary, and comment. Select of of these columns from the SQL query except for the comment, and then when the report is generated have the user be prompted for what the want the comment to be for every employee in the report?

    That is, have the user generating the report enter in a different comment for EACH employee. (ie Joe Smith's comment is "good worker and John Smith's comment is "come to work late on Tuesdays and Thursdays", Sally Jones' comment is "Expert in C++" etc.) as the reports is being built for each row returned from the query.

  • For each row of a table call a pl/sql function

    Hi,
    i have a search form in adf like this:
    parameter1:___
    parameter2:____
    buttonSearch
    Table with results
    field1 field2 field3
    row1 ------ --------- -------
    row2 ------ --------- -------
    row3 ------ --------- -------
    The user inputs the parameters 1 and 2 then press buttonSearch and the query execute and returns rows 1 to 3.
    What i need is for each row call pl/sql function and passed the parameter 1 and 2 and field 1 to 3 (plsql function recives 5 parameters (parameter1, parameter2, field1 , field2 and field3) )
    my buttonSearch call a java class that execute ExecuteWithParamters method.
    I create the call to my plsql function on Application module class and then export as a java interface.
    So i have the function to use in the viewcontroller layer, but i don't know where to use it, and how to pass the paramters: the parameter 1 and 2 that user inputs and the row fields.....
    any ideas....
    thanks!!

    Hi,
    for this you need to call the PLSQL function upon table rendering, which means that you need a field in the table referencing a managed bean. In the managed bean you can use #{row} and resolve it using a ValueExpression. #{row} gives you access to the current rendered row (this is why you need to do it when the table renders) and thus allows you to call getAttribute(name) to get the values of field 1 - 3. The search field value you should get through the bindings reference (assuming the search form uses ADF). Then you create an operation binding for the executeWithParameters and call operationBindingName.getParamsMap().put(argname, argvalue); on it.
    Frank
    Ps.: I am concerned about the performance you get and wonder if it isn't possible to create a transient attribute that executes the function and displays the results. As I understand, the search parameters are only to filter the result set, which you still can do

  • Horizontal lines for each rows in the rtf template

    Hi,
    I am a newbie for XML Publisher. I just created a XML Publisher report for Vendor invoices. But for each invoice/invoice line rows I am getting a horizontal line which separates each row. But I just wanted the vertical line to separate the columns and not for the rows.
    For example, the output looks like
    Invoice number | Item Description| Quantity|
    123__________| xyz__________|_____30 |
    _____________| xyz__________|_____30 |
    _____________| xyz__________|_____30 |
    345__________| xyz__________|_____30 |
    I am getting the report some this like this. But I need the report like below,
    Invoice number | Item Description| Quantity|
    123__________| xyz__________|_____30 |
    _____________| xyz__________|_____30 |
    _____________| xyz__________|_____30 |
    345__________| xyz__________|_____30 |
    (Please consider the ____ as space)
    Please suggest me some solution. tons of thanks in advance.

    Hi Vetsrini,
    Thanks for your prompt reply. I hope I had put the tag that you had mentioned. But anyhow I had sent your the template and the sample XML file to see the output.
    I have one more question also I want a curvey edge for the table and no tthe sharp edge like this _|. If possible please suggest for this also.
    Looking forward for your reply.
    Hope your mail id is fusion{DoT}object[AT]gmail[dOt]com

  • How to change VO's dynamically for a item for each row in advanced table?

    Hi All,
    We had a requirement to filter the employees based on the search criteria table. I am using advanced table for developing search criteria.
    In that table I am having three columns. Operator (messagechoice), Criteria Type (messagechoice), and Criteria value (messageLovInput). Also 'Add Another Row' functionality is available.
    My requirement is:
    First Row:(Initial Row)
    When the user selects a value in Criteria Type, only the values that are relevant to that type should be displayed in the Criteria Value.
    Second Row: (when the user selects Add Another Row button)
    When the user selects a value in Criteria Type, only the values that are relevant to that type should be displayed in the Criteria Value.
    The problem I am facing here is, the Criteria Value column is pointing to only one VO at design time. But wee need to change that VO dynamically without disturbing other rows depending on the Criteria Type value.
    Is it possible to do so?
    Note: User can add n number of conditions as he want.
    Can anyone help how to acheive this.
    Regards,
    Sundeep.

    Check Dynamic Poplist section under Standard Web Widgets in Chapter 4 of OA Framework Developers guide.

  • Select count(*) for each row of a table

    Hello All,
    Following query gives a statistics for each user (how many items he owns, home many tickets authored, how many objects he is subscribed to etc...)
    select auser.userid,
    (select count(*) from item where owner like '%' || auser.id || '%') ITEM_OWNER_CNT,
    (select count(*) from tkt where originator = auser.id) TKT_ORIGINATE_CNT,
    (select count(*) from tkt where assigned_to = auser.id) TKT_QA_CNT,
    (select count(*) from tkt where create_user = auser.id) TKT_AUTHOR_CNT,
    (select count(*) from subscriptions where subscriber_id = auser.id) SUBSCRIPTION_CNT
    from
    user auser
    I was not happy with the performance of this query, so I tried the same using group by. The performance was even worse.
    Is there any other option for me to try? Please advice.
    Thanks,
    Sathish

    Hi, Sathish,
    As SBH said, a lot depends on your data. Please post some sample data (CREATE TABLE adn INSERT statemetns) for all tables, and the results you want from that data. Describe and give examples of any relationships that are not one-to-one..
    You probably want to do joings, like SBH suggested, rather than scalar sub-queries.
    The connection between the auser and item tables
    (select count(*) from item where owner like '%' || auser.id || '%') ITEM_OWNER_CNT,is very suspicious. Perhaps the item table is poorly designed, and the query would be faster if that table were changed. Is changing the design of the item table an option?
    You should be able to get all the information from the tkt table in one pass. It looks like you need to unpivot the data, so instead of one row per ticket (with 3 different people connected to it), there are 3 rows per ticket, each with only 1 person referenced. This is not necessarily a bad table design. Unpivoting, even more than most other things, depends on your database version, so you'll have to tell what version of Oracle you're using.

  • ALV: Dropdown list individual for each line of the table

    Hi
    Question.. I would like to make a dropdown list for a field in the ALV list. The dropdown list is not the difficult point. But this dropdown list should be based on the line item.
    Example:
    Material 100.100     has plants (10, 20, 30)
    Material 100.800     has plants (60, 70)
    so the ALV list should show in the dropdown menu only the plants that this material has.
    As I'm not sure, that my explanations are any good, here a example:
    <u>
    ALV-List</u>
    Material       Description             Plants
    100.100        Screwdriver             (Dropdown list shows only 10,20,30)
    100.800        Hammer                  (Dropdown list shows only 60,70).
    Can anyone tell me if this is feasable? And if so how? Is it do-able with this method?
      call method grid->set_drop_down_table
        exporting
          it_drop_down = lt_dropdown.
    The program BCALV_EDIT_07 has sort of two different dropdown lists.. but I have more then two materials, there would be many lists to create.. (many drop_down_handle's)
    Any other idea?
    I know, this is a tricky one...
    Thanks
    Petra
    Message was edited by:
            Petra

    hi
    i have a code for drop down list use this
    this code is for selection-screen deop-down list yu can add this same code in ALV
    REPORT  ZCHETANA_PRAC10                         .
    Type-pools: VRM.
    data: name type vrm_id,
          list_month type vrm_values,
          list_year type vrm_values,
          value type vrm_value.
    selection-screen: begin of block b with frame.
    parameter: p_year(10) type c as listbox visible length 10,
               p_month(10) type c as listbox visible length 10.
    selection-screen: end of block b.
    at selection-screen output.
    value-key = 'JAN'.
    value-text = 'JAN'.
    append value to list_month.
    value-key = 'FEB'.
    value-text = 'FEB'.
    append value to list_month.
    value-key = 'MAR'.
    value-text = 'MAR'.
    append value to list_month.
    value-key = 'APR'.
    value-text = 'APR'.
    append value to list_month.
    value-key = '1998'.
    value-text = '1998'.
    append value to list_year.
    value-key = '1999'.
    value-text = '1999'.
    append value to list_year.
    value-key = '2000'.
    value-text = '2000'.
    append value to list_year.
    CALL FUNCTION 'VRM_SET_VALUES'
      EXPORTING
        ID                    = 'P_MONTH'
        VALUES                = list_month
    EXCEPTIONS
      ID_ILLEGAL_NAME       = 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.
    CALL FUNCTION 'VRM_SET_VALUES'
      EXPORTING
        ID                    = 'P_YEAR'
        VALUES                = list_year
    EXCEPTIONS
      ID_ILLEGAL_NAME       = 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.
    start-of-selection.
    write:/ p_year,
           p_month.

  • How to add a delete button on each row of the table.

    i create a table with a list , and i add a new column.
    and then i drag a delete botton from the list operation to the column.
    when i create several rows. and click any delete botton of the new created rows. all the new created rows will be deleted.
    rows that already exist when the page render are not influenced.and when i click these rows' delete botton,
    just the current row will be delete.
    that's because when i click the new created rows' delete botton,all the new created botton in this column will automatically be clicked.
    i think adf consider all the delete botton are the same one.
    is it the table bug? please tell me how to resolve this problem. thanks.
    Edited by: 917391 on 2012-3-21 下午6:53
    Edited by: 917391 on 2012-3-21 下午10:07
    Edited by: 917391 on 2012-3-21 下午10:16

    i don't use the adf BC, so it is not a VO. it's just a service method that return a list.
    and i create the datacontrol and drag it to the page.
    Edited by: 917391 on 2012-3-21 下午10:26

  • Update primary key with a tabular form based on a select list for each row

    Hello!
    I've two tables: Table1 with only one column (primary key) is a foreign key for table2.column1 (primary key). There is also a second primary key column in table2.
    Now I want to change the primary key values in table2.column1 with a tabular form (MRU) based on a select list (LOV based on table1.column1) for each row.
    The user should be able to choose for every row a new value from the select list to change the old primary key value at this position.
    How can I do this with ApEx?
    I've the tabular form and so on, but at the moment I get the following error:
    "Error in mru internal routine: ORA-20001: Fehler in MRU: row= 1, ORA-20001: ORA-20001: Die aktuelle Version der Daten in der Datenbank wurde geändert, seit der Benutzer einen Update-Prozess eingeleitet hat. ..."
    Thank you for your support!
    Kay

    Hello!
    I've two tables: Table1 with only one column (primary key) is a foreign key for table2.column1 (primary key). There is also a second primary key column in table2.
    Now I want to change the primary key values in table2.column1 with a tabular form (MRU) based on a select list (LOV based on table1.column1) for each row.
    The user should be able to choose for every row a new value from the select list to change the old primary key value at this position.
    How can I do this with ApEx?
    I've the tabular form and so on, but at the moment I get the following error:
    "Error in mru internal routine: ORA-20001: Fehler in MRU: row= 1, ORA-20001: ORA-20001: Die aktuelle Version der Daten in der Datenbank wurde geändert, seit der Benutzer einen Update-Prozess eingeleitet hat. ..."
    Thank you for your support!
    Kay

  • How to process a block for each row in an internal table....

    Hi experts....
    In po approval workflow the scenario is like this.... for each po there may be more than one approver. approvers list i am maintaining in the ztable. list of approvers(no of approvers) is decided by the po value. I have collected these approvers into internal table. now i have to process a block ( approving or rejecting the po... )in the workflow for each row in the internal table.
    how can i do this. based on the decision of the 1st approver  approves the po then it should go to next approver in the internal table...otherwise end the workflow.....
    Please help me......

    i have created an internal table in the workflow container in which i am getting the list of approvers....
    how can i loop the internal table in the workflow...?
    how can i know the index of the loop in the workflow.....(will sy-index work here....? so that i can use loop until step in the main workflow to call the subworkflow..so that if sy-index is greater than no of entires in the itab then i can come out of the loop)

  • Raise expection for each row if returned set contains x

    Hello Guys,
    I have the following code and almost gave up on the idea to raise an exception and print
    a line for each row where the sales price is < 10. I know how this works with a CURSOR but I want to try it without it. Thinking about it let me to the conclusion that this is not possible to act on individual row results on a set based operation. I will have to use a CURSOR (not set based so I can look at each row).
    Am I thinking correctly?
    (Code example deleted due to confusion)
    Code example deleted due to confusion
    Edited by: metalray on 10.11.2010 01:07

    Hi 3360,
    I am using PL/SQL. I can make my point without any code.
    The question, in a different format is this:
    Can I throw an whatever exception (or dbms_output put line) for individual rows WITHOUT using a cursor.
    My answer (and I just need clarification on this):
    *(1)* No, because anything apart from a cursor is set-based and set-based operations (select, join, union)
    can not through exceptions on individual rows.
    *(2)* Yes, you can have a DBMS_OUTPUT.PUT_LINE with whatever exception on a set based operation
    for each individual row that causes the exception (I dont think this answer is true :)
    @Agustin UN, thanks for that. I know that is possible :) The problem is,
    that I dont think I can print or fetch each individual row that causes the "exception" since
    it is treated as a set. - I am welcome for someone to tell me that it work nevertheless

  • Use labview to read an Excel file to some control and add a checkbox for each row

      As the subject say,I need to use labview to read an excel file,and show it in some control,such as mclb;then ,I should add an checkbox for each row,enable me to choose the row i want.What should I do ? Many Thanks.
    Solved!
    Go to Solution.

    Hi,
    to answer your question:
    - read an excel file
    - show it in some control, such as a MCLB
    - add an checkbox for each row
    - choose the row you want
    Hint to make it easier: I wouldn't use checkboxes, as the MCLB already allows to select rows by mouseclick…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

Maybe you are looking for