Put loop of variables into single array with formatting (PHP)

I have the following loop;
<?php
$i=1;
while($i<=$num_rows)
$tempquantity = "extra".$i."quantity";
$tempcomments = "extra".$i."comments";
$tempname = "extra".$i."name";
$tempprice = "extra".$i."price";
$$tempquantity = $_POST['extra' . $i . 'quantity'];
$$tempcomments = $_POST['extra' . $i . 'comments'];
$$tempname = $_POST['extra' . $i . 'name'];
$$tempprice = $_POST['extra' . $i . 'price'];
print "Extra name: " . $$tempname;
print "<br />";
print "Extra price: " . $$tempprice;
print "<br />";
print "Quantity required: " . $$tempquantity;
print "<br />";
print "Client comments: " . $$tempcomments;
print "<br /><br />";
  $i++;
?>
Which, since there are 3 rows, outputs the following;
Extra name: dfvgfddf
Extra price: 4
Quantity required: 67
Client comments: gtfh
Extra name: wewew
Extra price: 34
Quantity required: 45
Client comments: thtrt
Extra name: ewewe
Extra price: 43
Quantity required: 12
Client comments: gdfgg
What I want to be able to do is show the output above in a PHP email body variable, which I think this means that the loop of varaibles needs to be in one single array variable since coding in an email body variable is not allowed. How do I put a loop of variables like this into a single variable, and how to I keep the <br /> tags and names in front of the varaibles ('Extra name:' etc), so it looks as it should in the PHP email body?
Thanks in advance

Hi Murray,
This is the code that sends the email;
$to = "$renteremail";
$subject = "Request confirmation";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: website";
$body = "
Your reference number is <strong>$rrnumber</strong>.
<br />
<br />
Below is a summary of your request details;
<br /><br /><strong>Accommodation name</strong>: $accomm_name
<br /><strong>Accommodation type</strong>: $accomm_type
<br /><strong>Board-type</strong>: $ptbt
<br /><strong>Max. capacity</strong>: $ptc
<br /><strong>Check-in date</strong>: $passdate
<br /><strong>Number of nights</strong>: $passnights
<br /><br /><strong>Renter's name</strong>: $rentername
if (mail($to, $subject, $body, $headers)) {$messagesent = 'yes';}
So the three loop items with their four respective variables should go at the end of the list of variables above after 'Renters name'.
I also need to put the variables generated by the loop into a single database feild, so if possible all should go into one variable.
Thanks

Similar Messages

  • Combining Multiple Rows into single row with multple columns

    Hi Experts,
    I have the following requirement, kindly help me.
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.
    ID NAME DEPT1 DEPT2 DEPT3
    1 Sam 10 20
    2 alex 30 40 50
    3 vinod 60 70
    It's urgent requirement, kindly help me.
    Thanks in advance.

    Right I've had my drink, so what was this "urgent" question then?
    798616 wrote:
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.Dynamic numbers of columns eh! Tricky.
    If you understand how SQL statements are executed it's along these lines...
    1. Open Cursor
    2. Parse SQL statement and determine columns
    3. Bind in any input values
    4. Fetch data
    5. Bind out values to columns
    6. Repeat step 3 until no more data
    7. Close cursor
    Now, you're expecting that you can determine the columns (step 2) from the fetched data (step 4 onwards). You can't. The SQL engine needs to know the expected columns before any data is fetched so, it can't base the number of columns on the data itself.
    If you need that requirement, you would need to query the data first and build up a dynamic query based on the data and then execute that dynamically built query to fetch the data and pivot it into those columns, which means that you have queried the data twice. Not good practice and not good (or simple) coding.
    What you're talking of doing is something that should be handled at the presentation/interface layer, not as part of the data fetch.
    Typically these sorts of things are handled most easily in report generation/writer tools such as Oracle Reports, Business Objects etc. where they fetch the data from the database and then process it to format it on the display, pivoting the results as required.
    It's not something that lends itself to be easily achieved in SQL. Yes, SQL can do pivoting of data quite easily, but NOT with a dynamic number of columns.
    If you were to specify that there is a maximum number of columns that you could get (rather than wanting it dynamic), then you can do it simply in SQL with the max-decode method...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select deptno, ename, row_number() over (partition by deptno order by ename) as rn from emp)
      2  --
      3  select deptno
      4        ,max(decode(rn,1,ename)) as ename1
      5        ,max(decode(rn,2,ename)) as ename2
      6        ,max(decode(rn,3,ename)) as ename3
      7        ,max(decode(rn,4,ename)) as ename4
      8        ,max(decode(rn,5,ename)) as ename5
      9        ,max(decode(rn,6,ename)) as ename6
    10        ,max(decode(rn,7,ename)) as ename7
    11        ,max(decode(rn,8,ename)) as ename8
    12        ,max(decode(rn,9,ename)) as ename9
    13        ,max(decode(rn,10,ename)) as ename10
    14  from t
    15  group by deptno
    16* order by deptno
    SQL> /
        DEPTNO ENAME1     ENAME2     ENAME3     ENAME4     ENAME5     ENAME6     ENAME7     ENAME8     ENAME9     ENAME10
            10 CLARK      KING       MILLER
            20 ADAMS      FORD       JONES      SCOTT      SMITH
            30 ALLEN      BLAKE      JAMES      MARTIN     TURNER     WARD
    SQL>

  • Convert variable into an array

    I have variable, abc; whose value is in the format val1,val2,val3,..
    I want to convert it into an array, like that arr[0]=val1; arr[1]=val2; so on. How can I do this?
    Usman

    examine this class that I did
    import java.lang.*;
    public class ReadString {
    public static void main(String[] args){
    String abc = "1,2,3,4,5,6";
    StringBuffer abc2 = new StringBuffer(abc);
    int arrayLength = abc2.length(); //get length
    int[] abcFinal = new int[6];
    for (int i=0; i<arrayLength; i++) { //test characters
         int anIndex;
         if (!(abc2.substring(i,i+1)).equals(",")) { //if it is a number
         //(i/2) is ta little formula to be able to assign the
         //right index in the intArray to the number
         anIndex = (i/2);
         //set value to array
         abcFinal[anIndex] = Integer.parseInt(abc2.substring(i,i+1));
    for (int j=0;j<abcFinal.length;j++ ) {
         System.out.println("i = " + j + " value = " + abcFinal[j]);
    }//end main
    }//end class

  • Putting 7 table fields into one field with line breakes included!

    Hi People
    I Need to assamble 7 fields from a view, into one field with some line brakes in Reports, how do I do that???
    E.g :
    Field names : Name, Collection1, StreetName, StreetNo, ExtraCity, ZipCode, City
    Should be put into one field called address and be displayed like this
    Name
    Collection1
    StreetName StreetNo
    ExtraCity
    ZipCode City
    I hope someone can help me *S
    /Stig :-)

    The following should give you some idea. It might depend if you run your report on Windows or Unix.
    select
    Name        || decode(Name, null, null, chr(13)||chr(10))||
    Collection1 || decode(Collection1, null, null, chr(13)||chr(10))||
    StreetName  || decode(StreetName, null, null, ' '||StreetNo||chr(13)||chr(10))||
    ExtraCity   || decode(ExtraCity, null, null, chr(13)||chr(10))||
    ZipCode     || decode(ZipCode, null, null, ' '||City )
    from MyView

  • How to import files with static variables into a block with methods?

    i have a problem. is it possible to import files with static variables into tags like
    <%!
    //here i want to import a file named settings.inc
    //whitch is used to set jdbc constants like url,driver,...
    private void method() {
    private void method2() {
    %>
    <%@include file="xy"%>//dosn�t work above
    //only in <%%>tag

    This should be done using either the Properties class or ResourceBundle. Ex.
    <%
    ResourceBundle resBun = ResourceBundle.getBundle(String resource);
    String username = resBun.getString("username");
    String password = resBun.getString("password");
    // etc
    %>

  • How to put a jsp variable into a javascript function?

    Please read the following coding. I want to pass the variable ans from jsp to the function check_answer() of javascript. ans is a string got from database. But I cannot put the variable ans into the Javascript function. Can anyone help?
    <script language="Javascript">
    function check_answer() {
    if (testing.result.value==ans ){
    window.alert("You have got 10 marks.");
    </script>
    <body>
    <form name="testing"...>
    <%
    ResultSet rs = stmt.executeQuery("select * from level where...");
    while(rs.next())
    out.println("<tr>");
    out.println("<td>" + rs.getString("question") + "</td>");
    ans = rs.getString("answer");
    out.println("</tr>");
    out.println("<input type='text' name='result'>);
    out.println("<input type='button' value='Enter' onclick='check_answer()'>");
    %>

    The following should be able to pass ans.
    <script language="Javascript">
    function check_answer(ans) {
    if (testing.result.value==ans ){
    window.alert("You have got 10 marks.");
    </script>
    <body>
    <form name="testing"...>
    <%
    ResultSet rs = stmt.executeQuery("select * from level where...");
    while(rs.next())
    out.println("<tr>");
    out.println("<td>" + rs.getString("question") + "</td>");
    ans = rs.getString("answer");
    out.println("</tr>");
    out.println("<input type='text' name='result'>);
    out.println("<input type='button' value='Enter' onclick='check_answer('<%= ans%>')'>");
    %>jag

  • How to alternate data storage into 2 arrays with an analog square wave input? (seems that the retriggera​ble function is not supported by my PXI card)

    Hi!  
    I'm trying to have an analog square wave input determine where data gathered from a second analog input channel is stored.  I want data to be stored to one array during the high signal period of the square wave and data to be store to another array during the low signal period of the square wave.  The square wave I'm using is of constant frequency (8.3 Hz).  I believe I need to use an analog input wave as opposed to a onboard clock or other timing mechanism because my square wave is also being used to modify the input going into my experimental setup.  Thus the data storage needs to be correlated to the timing of the data modification in the experiment.  I tried to use the retriggerable property node function, but receive error 200452, which I think means that my PXI card (6115) can't support this retriggerable function.  So I'm looking for other ways to accomplish alternating data storage in response to an incoming analog square wave.  Any help would be GREATLY appreciated... Thanks!  (I'm also quite new with LabView so toddler-type explanations would probably be most useful  )
    -Shari
    (LabView version 8.6)
    Attachments:
    Pulsed_Acq_Switch_Simplified.vi ‏47 KB

    Hello Shari,
          I am looking at your situation and it seems very intriguing.  after downloading your file I have a couple questions to ask if you don't mind answering.
          Currently in your program you are only taking one sample of data at a time,  this could lead to uneven sampling.  Would you like to sample at a consistent rate  (say 10 Kilosamples of data a second?)  if so what type of card are you using?
          Also,  Do you want your data to be in a 2-D array of data?
    Best Wishes,
    Daniel

  • Loop movie on a single frame with AS2?

    Hi, i'm animating a web banner, which is supposed to loop infinite times. The thing is, i learnt to use tweening prototype for my animation, so the entire code is written on a single frame.
    Is there a way to loop the entire movie at the end?

    Thanks! but I still need help.
    Ok, let's say this is the code:
    function iniciar (){
    //INTRO//
    _root.fondo._x=2632;
    _root.fondo._y=223;
    _root.fondo.tween("_x",-38,25,"easeOutCubic",0.5)
    _root.bloqueintro._x=535
    _root.bloqueintro._y=226
    _root.bloqueintro.tween("_x",-600,1.5,"easeOutCubic",6.5)
    _root.opt._x=468
    _root.opt._y=-50
    _root.opt.tween("_y",146,1.5,"easeOutCubic",1.5)
    _root.opt.tween("_x",-270,1.5,"easeOutCubic",6.5)
    _root.esp._x=530
    _root.esp._y=198
    _root.esp._yscale=0
    _root.esp.tween("_yscale",100,1,"easeOutBounce",2.5)
    _root.esp.tween("_x",-459,1.5,"easeOutCubic",6.5)
    _root.de._x=621
    _root.de._y=246
    _root.de._yscale=0
    _root.de.tween("_yscale",100,1,"easeOutBounce",2.5)
    _root.de.tween("_x",-368,1.5,"easeOutCubic",6.5)
    _root.trab._x=664
    _root.trab._y=292
    _root.trab._yscale=0
    _root.trab.tween("_yscale",100,1,"easeOutBounce",2.5)
    _root.trab.tween("_x",-325,1.5,"easeOutCubic",6.5)
    //CONECTOR//
    _root.conector._x=1659;
    _root.conector._y = 244;
    _root.conector.tween("_x",-800,1.5,"easeOutCubic",6.5);
    _root.conector2._x=-800;
    _root.conector2._y = 244;
    _root.conector2.tween("_x",1924,1.5,"easeOutCubic",13);
    _root.conector3._x=1924;
    _root.conector3._y = 244;
    _root.conector3.tween("_x",-800,1.5,"easeOutCubic",21);
    _root.conector4._x=-800;
    _root.conector4._y = 244;
    _root.conector4.tween("_x",1924,1.5,"easeOutCubic",27);
    iniciar();
    So the whole animation is now into a function body. Still, how can i loop that function, if i only have one frame?

  • Store XML node value into an array with node element name

    Hi,
    I have the following code that displays the node element with the
    corresponding node value. I want to store the values in an array in
    reference to the node name.
    i.e.
    XML (my xml is much bigger than this, 300 elements):
    <stock>
    <symbol>SUNW</symbol>
    <price>17.1</price>
    </stock>-----
    would store the following:
    *data[symbol] = SUNW;*
    *data[price] = 17.1;*
    Thanks in advance,
    Tony
    test.jsp
    Here's my source code:
    <html>
    <head>
    <title>dom parser</title>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="dombean.*" %>
    </head>
    <body bgcolor="#ffffcc">
    <center>
    <h3>Pathways Info</h3>
    <table border="2" width="50%">
    <jsp:useBean id="domparser" class="dombean.MyDomParserBean" />
    <%
    Document doc = domparser.getDocument("c:/stocks/stocks.xml");
    traverseTree(doc, out);
    %>
    <%! private void traverseTree(Node node,JspWriter out) throws Exception {
    if(node == null) {
    return;
    int type = node.getNodeType();
    switch (type) {
    // handle document nodes
    case Node.DOCUMENT_NODE: {
    out.println("<tr>");
    traverseTree
    (((Document)node).getDocumentElement(),
    out);
    break;
    // handle element nodes
    case Node.ELEMENT_NODE: {
    String elementName = node.getNodeName();
    //if(elementName.equals("MOTHER-OCC-YRS-PREVIOUS")) {
    //out.println("</tr>");
    out.println("<tr><td>"+elementName+"</td>");
    NodeList childNodes =
    node.getChildNodes();     
    if(childNodes != null) {
    int length = childNodes.getLength();
    for (int loopIndex = 0; loopIndex <
    length ; loopIndex++)
    traverseTree
    (childNodes.item(loopIndex),out);
    break;
    // handle text nodes
    case Node.TEXT_NODE: {
    String data = node.getNodeValue().trim();
    //if((data.indexOf("\n")  <0) &#38;&#38; (data.length() > 0)) {
    out.println("<td>"+data+"</td></tr>");
    %>
    </table>
    </body>
    </html>
    {code}
    *MyDomParserBean.java*
    Code: package dombean;
    {code:java}
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.*;
    public class MyDomParserBean
    implements java.io.Serializable {
    public MyDomParserBean() {
    public static Document
    getDocument(String file) throws Exception {
    // Step 1: create a DocumentBuilderFactory
    DocumentBuilderFactory dbf =
    DocumentBuilderFactory.newInstance();
    // Step 2: create a DocumentBuilder
    DocumentBuilder db = dbf.newDocumentBuilder();
    // Step 3: parse the input file to get a Document object
    Document doc = db.parse(new File(file));
    return doc;
    {code}
    Edited by: ynotlim333 on Sep 24, 2007 8:41 PM
    Edited by: ynotlim333 on Sep 24, 2007 8:44 PM
    Edited by: ynotlim333 on Sep 24, 2007 8:45 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I still need to store it in an array because its 300 elements in the XML stocks.
    I've done the following but its not working, i'm getting error codes. I think its an easy fix. I'd also like to pass a String instead of a .xml document b/c my xml is stored inside a DB. Any suggestions on that?
    <html>
    <head>
    <title>dom parser</title>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="org.*" %>
    </head>
    <body bgcolor="#ffffcc">
    <center>
    <h3>Pathways Info</h3>
    <table border="2" width="50%">
    <jsp:useBean id="domparser" class="org.MyDomParserBean" />
    <%
    Document doc = domparser.getDocument("c:/stocks/stocks.xml");
    traverseTree(doc, out);
    %>
    <%!
            public String element_store = null;
            public String[] stock_data = new String[400];
            private void traverseTree(Node node,JspWriter out) throws Exception {
            if(node == null) {
               return;
            int type = node.getNodeType();
            switch (type) {
               // handle document nodes
               case Node.DOCUMENT_NODE: {
                 out.println("<tr>");
                 traverseTree
                 (((Document)node).getDocumentElement(),
                 out);
                 break;
              // handle element nodes
              case Node.ELEMENT_NODE: {
                String elementName = node.getNodeName();
                element_store = elementName;
                 //if(elementName.equals("MOTHER-OCC-YRS-PREVIOUS")) {
                   //out.println("</tr>");
                 NodeList childNodes =
                 node.getChildNodes();     
                 if(childNodes != null) {
                    int length = childNodes.getLength();
                    for (int loopIndex = 0; loopIndex <
                    length ; loopIndex++)
                       traverseTree
                       (childNodes.item(loopIndex),out);
                  break;
               // handle text nodes
               case Node.TEXT_NODE: {
                  String data = node.getNodeValue().trim();
                  if((data.indexOf("\n")  <0) && (data.length() > 0)) {
                  out.println("<tr><td>"+element_store+"</td>");
                  out.println("<td>"+data+"</td></tr>");
                  stock_data[element_store]=data;
    %>
    </table>
    </body>
    </html>

  • SQL - Multiple Fetch into Single Column with Comma Separator

    Hello Experts,
    Good Day to all...
    I need your help on following scenarios. The below query returns set of titleID strings. Instead of printing them one below the other as query output, I want the output to be in batch of 25 values.i.e each row should have 25 values separated by comma. i.e If there are 100 titles satisfying the output, then there should be only four rows with and each row having 25 titles in comma separated manner.
    SELECT DISTINCT title_id
               FROM pack_relation
              WHERE package_id IN (      SELECT DISTINCT fa.package_id
                                                    FROM annotation fa
                                                GROUP BY fa.package_id
                                                  HAVING COUNT
                                                            (fa.package_id) <100);I tried with the PL/SQL block; whereas it is printing all the values continously :(
    I need to stop with 25 values and display.
    If its possible with SQL block alone; then it would be of great help
    DECLARE
       v_str   VARCHAR2 (32767)  := NULL;
       CURSOR c1
       IS
         SELECT DISTINCT title_id
               FROM pack_relation
              WHERE package_id IN (      SELECT DISTINCT fa.package_id
                                                    FROM annotation fa
                                                GROUP BY fa.package_id
                                                  HAVING COUNT
                                                            (fa.package_id) <100);
    BEGIN
       FOR i IN c1
       LOOP
          v_str := v_str || ',' || i.title_id;
       END LOOP;
       v_str := SUBSTR (v_str, 2);
       DBMS_OUTPUT.put_line (v_str);
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line ('Error-->' || SQLERRM);
    END;Thanks...

    You can use CEIL
    Sample code
    SELECT
        nt,
        LTRIM(MAX(SYS_CONNECT_BY_PATH(val,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
    FROM
            SELECT
                val,
                nt,
                ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val)    AS curr,
                ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val) -1 AS prev
            FROM
                    SELECT
                        level                          AS val,
                        ceil(rownum/3)  as nt /* Grouped in batches of 3 */
                    FROM
                        dual
                        CONNECT BY level <= 10
    GROUP BY
        nt
        CONNECT BY prev = PRIOR curr
    AND nt              = PRIOR nt
        START WITH curr = 1;
            NT CONCAT_VAL
             1 1,2,3
             2 4,5,6
             3 7,8,9
             4 10Your code
    SELECT
        nt,
        LTRIM(MAX(SYS_CONNECT_BY_PATH(title_id,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
    FROM
            SELECT
                title_id,
                nt,
                ROW_NUMBER () OVER (PARTITion BY nt ORDER BY title_id)   AS curr,
                ROW_NUMBER() OVER (PARTITION BY nt ORDER BY title_id) -1 AS prev
            FROM
                    SELECT
                        title_id,
                        ceil(rownum/25) AS nt /* Grouped in batches of 25 */
                    FROM
                        pack_relation tdpr
                    JOIN annotation fa
                    ON
                        tdpr.package_id = fa.package_id
                    GROUP BY
                        title_id,
                        fa.package_id
                    HAVING
                        COUNT (fa.package_id) < 500
    GROUP BY
        nt
        CONNECT BY prev = PRIOR curr
    AND nt              = PRIOR nt
        START WITH curr = 1;

  • Merge 2 rows into single row with data update?

    hello all,
    i have a table with below data,
    declare @tbl table (uid int, uname varchar(10), start_dt date, end_dt date)
    insert into @tbl values (1, 'env1', '4/4/2010', '5/5/2012')
    insert into @tbl values (2, 'env2', '5/4/2010', '6/6/2012')
    --earlier start data is '4/4/2010' from 'env1'
    --latest end data is '6/6/2012' from 'env2'
    insert into @tbl values (3, 'env1', '3/3/2010', '4/4/2012')
    insert into @tbl values (4, 'env2', '2/2/2010', '5/5/2012')
    --earlier start data is '2/2/2010' from 'env2'
    --latest end data is '5/5/2012' from 'env2'
    insert into @tbl values (5, 'env1', '8/8/2010', '12/12/2012')
    insert into @tbl values (6, 'env2', '9/9/2010', '10/10/2012')
    --earlier start data is '8/8/2010' from 'env1'
    --latest end data is '12/12/2012' from 'env1'insert into @tbl values (6, 'envX', '9/9/2010', '10/10/2012')insert into @tbl values (6, 'envY', '9/9/2010', '10/10/2012')
    i need to merge 2 rows for column  "uname" having value "env1" & "env2" to "envZ" and need to capture earlier start date and latest end date from both and update with new.
    the desire output should be,
    declare @tbl table (uid int, uname varchar(10), start_dt date, end_dt date)
    insert into @tbl values (1, 'envZ', '4/4/2010', '6/6/2012')
    insert into @tbl values (4, 'envZ', '2/2/2010', '5/5/2012')
    insert into @tbl values (5, 'envZ', '8/8/2010', '12/12/2012')
    insert into @tbl values (6, 'envX', '9/9/2010', '10/10/2012')
    insert into @tbl values (6, 'envY', '9/9/2010', '10/10/2012')
    note - i must need to update one row and delete other row as i can't insert new rows (having huge data with other columns also).
    please suggest optimize query. thanks!

    Which version and edition of SQL Server are you using?
    Whenever there is a row with 'env1', there is a corresponding 'env2' and vice versa? 
    The row with 'env2' is always after the row with 'env1'?   (uid+1)
    If the answers are yes to both questions above, here's a possibility:
    -- code #1 v3
    ;with
    ENVZ as (
    SELECT uid= case when T1.start_dt <= T2.start_dt then T1.uid else T2.uid end,
    start_dt= case when T1.start_dt <= T2.start_dt then T1.start_dt else T2.start_dt end,
    end_dt= case when T1.end_dt > T2.end_dt then T1.end_dt else T2.end_dt end
    from @tbl as T1
    inner join @tbl as T2 on T2.uid=T1.uid+1 and T2.uname='env2'
    where T1.uname = 'env1'
    MERGE
    into @tbl as T3
    using ENVZ as T4
    on T3.uid = T4.uid
    when matched and (T3.uname in ('env1','env2')) then
    UPDATE set T3.uname= 'envZ',
    T3.start_dt= T4.start_dt,
    T3.end_dt= T4.end_dt
    when not matched by source and (T3.uname in ('env1','env2')) then
    DELETE;
    The table @tbl is read three times in the above code. There are probably ways to optimize the above code. Or even other more efficient approach.
    José Diz     Belo Horizonte, MG - Brasil

  • Get matrix row data and put it into header field with formatted search ???

    Hi All,
    I ask your help concerning the following:
    On an invoice matrix I want to check all Itemgroup Codes of all items in the rows, if there are some rows' items with ItemGroupcode 101 and some others with anything else, then header field should be Y, otherwise N.
    My main problem is: how do I put a matrix row data to a header data with checking all rows in the matrix?
    A minor problem is that I can't get the formatted search to work on all rows when the formatted search is assigned to the user field in header.
    If I put the formatted search to a row field then the row field is filled with the proper value, but the same query assigned to the user field in header works only on the first row.
    What am I doing wrong?
    SELECT USEDPROD= CASE T0.ItmsGrpCod  WHEN 101 THEN Y ELSE N END FROM .[OITM] T0 WHERE T0.ItemCode = $[$38.1.0]
    (SBO 7.6)
    Any suggestions are welcome.
    Thanks.
    Bálint

    Dear Adele,
    Thanks for the answer. The major one cannot be solved. OK, I'll try to get a workaround.
    However I still do not understand why my query does not work in all selected rows, just in the first row, i.e. if I assign the query to a header field and I'm positioned in the first row it's OK, but when I add a new item to the second row or any of the next rows, the header field is not updated at all.
    Why is that so? Do you have any idea?
    Bálint

  • Rows into single column with comma seperator

    Hi Friends,
    I have the following Query
    select A.tradeid||','||A.TICKER||'|'||A.SUBORDINATION||'|'||A.CUSIP||'|'||A.DOCCLAUSE||'|'||A.CURRENCY from table A
    where A.ticker in ('LYME','GAADF') and A.tradeid in('456777')
    which is returning
    456777,LYME|SENIOR UNSECURED|Z1700990|MM|USD
    456777,GAADF|SENIOR UNSECURED|Z1246790|MM|USD
    I want the result set as:
    456777,LYME|SENIOR UNSECURED|Z1700990|MM|USD,456777,GAADF|SENIOR UNSECURED|Z1246790|MM|USD
    Please help me to get the result set
    Thanks,
    ragu.
    Edited by: user533548 on Apr 3, 2009 12:54 AM
    Edited by: user533548 on Apr 3, 2009 12:55 AM

    you could do
    select max (ltrim (sys_connect_by_path (tradeid||'|'||TICKER||'|'||SUBORDINATION||'|'||CUSIP||'|'||DOCCLAUSE||'|'||CURRENCY, ','), ','))
      from (
    select tradeid
         , ticker
         , subordination
         , cusip
         , docclause
         , currency
         , row_number() over (partition by tradeid
                                  order by null
                             ) rn
      from x)
    start with rn = 1
    connect by rn = prior rn + 1like in
    SQL> with x as
      2  (
      3  select 456777 tradeid ,'LYOE' ticker ,'SENIOR UNSECURED' subordination,'Z1830990' cusip,'MM' docclause,'USD'  currency from dual union all
      4  select 456777 tradeid ,'GAZDF','SENIOR UNSECURED','Z8446790','MM','USD' from dual
      5  )
      6  select max (
      7        ltrim
      8        (sys_connect_by_path (tradeid||'|'||TICKER||'|'||SUBORDINATION||'|'||CUSIP||'|'||DOCCLAUSE||'|'||CURRENCY
      9         , ',')
    10        , ',')) str
    11    from (
    12  select tradeid
    13       , ticker
    14       , subordination
    15       , cusip
    16       , docclause
    17       , currency
    18       , row_number() over (partition by tradeid
    19                                order by null
    20                           ) rn
    21    from x)
    22   start with rn = 1
    23   connect by rn = prior rn + 1
    24 
    SQL> /
    STR
    456777|GAZDF|SENIOR UNSECURED|Z8446790|MM|USD,456777|LYOE|SENIOR UNSECURED|Z1830990|MM|USD

  • Why do we put similar infoobjects into single dimension.

    Why do we put similar infoobjects(Char ex: 0material, 0matl_type, 0matl_group, 0matl_cat,  0mat_plant) into single dimension(MATERIAL DIMENSION). and other similar like(0CUSTOMER, 0SHIP_STCK, 0SOLD_TO, 0DIVISION, ZORD_MAT) into single dimension(CUSTOMER DIMENSION), What will happen if i put all these infoobjects into single Dimension, Can some one answer me in the system prospect, data base prospect  as well as performace point of view or may in general.
    Points will be given.............. thats what u definitely deserve for a right answer.

    Santosh,
    This is an important thing while deciding upon the dimensions. Its not the similar things we are putting together but based on the data realtion and cardinality we put the chars in a dimension. If dimensions are not properly designed the tables size increases drastically and lead to poor performance. Taking an example the relation between the chars in a dimension should be 1:m and not n:m. A material can have one material type and belons to one materila group for a plant is the relation which is a 1:n relation. Chars with high cardinality are put in separate dimensions instead of grouping with other chars.
    The grouping of classification groups (characteristics) whose content is logically connected, under a single generic term. If the dimension contains a characteristic whose value already uniquely determines the values of all other characteristics from a business-orientated viewpoint, then the dimension is named after this characteristic.

  • How do I put and sort string data into an array?

    I have a txt file that has the following sample data:
    Sample.txt----
    Jones Bill 12,500 Salesperson
    Adams Frank 34,980 Manager
    Adams John 23,000 Salesperson
    Thompson Joe 59,500 Trainee
    I need to incorporate each line of data into an individual array element, while using a user-defined method
    (ex. setAllValues(String last, String first, String salary, String job)
    How do I loop the data into the array to be displayed and what is the best way to do sorts on this sample data. Any code or clues would be super helpful.
    Sanctos

    If you set up an array of Strings you can use the java.util.Arrays.sort() method to sort it. If you need to sort arbitrary Objects (i.e. your 3 strings as a whole entity) your 3-way object will have to either implement Comparable or you could write a Comparitor class to do the ordering. Not much to it, though.
    Dom.

Maybe you are looking for

  • I downloaded Mavericks, and now ITunes won't open

    Although the iTunes icon is showing on the dock and in Launchpad and Finder, it won't open.

  • Why do all my word documents open when I open word

    why do all my word documents open when I open word

  • Ghost Images - Pages to PDF, Kinko's Printing

    I could really use some help here. I am trying to print about 8 pages of images & text in the Extreme Template. When I export the file to PDF everything looks fine, I then took it to kinko's to be printed on card stock and binded and when they did th

  • Solaris 8 intel platform problem

    I configured a wrong vga/video and monitor for my solaris. Now when it restarts, it comes at a place with message "Starting Desktop login at display 0" and hangs at this place. I can telnet my system from any other system and can work from there but

  • Running Flash on an iPad

    Hi all, Apple is giving out this list of applications (cloud-based, presumably) that they say help with running Flash on an iPad.  Does anyone have any experience with any of them?  Do they allow interactivity? Puffin Cloud Browse Onlive Desktop SkyF