Saving an invoice header and details in sql in one stored procedure.

I would like to create an invoice in visual studio 2008 with a header and x amount of details (every time it's different). I want to be able to bring it all into sql encapsulated in one begin and commit transaction so that if there is an error anywhere
on the way it can roll back and nothing will be saved to the database. 
Debra has a question

I have an article on my web site which includes a sample not too different from your situation. (In the sample data is read from a file, but that has little to do with the database communication.) Since you pass the data through TVPs, you can have the transaction
in the stored procedure:
http://www.sommarskog.se/arrays-in-sql-2008.html
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Keeping heading and detail on the same page

    Hi, I have a report with a group header section and a detail section.  How can I keep the heading section and all the detail section on the same page without starting each group on a new page?
    The detail section will have either 2 or 3 records with some of the objects set to grow if the data doesn't fit on one line.  This results in several changes of group appearing on the same page which is what I want.  However, what I don't want is the header section on one page with the detail section on the next, or the header and some of the detail records on one page with the rest of the detail records on the next.  What I would like is the report to start a new page if the header and all the detail records don't fit on the same page but without starting a new page for every group change.  How can I achieve this?

    you can put the group header and details into a sub report on the old group header section.
    then hide the details section

  • File content conversion - sender adapter for Header and detail records

    Hi Experts,
                     I am receiving a field of fixed length content format.(Header)The first line of the file will follow the structure X having some fields and (DetailRecord)subsequent lines in the file will follow structure Y having somes fields.There is no record identifier for Header and Detail records.In one file first line is Header records and remaining subsequent line is DetailRecord.What are the parameters we have to set for sender file content conversion parameters as i donot have any key field and key field value.And in one file we have only one header records ( first line) and n number of detail records from 2nd line onwards.
    Thanks
    Deepak

    Hi
    Refer the below fourm link,
    Flat file whitout id
    Regards
    Ramg.

  • XMLSequence EXTRACT HEAD and DETAIL in ORACLE 9.2

    Hi, sorry about my english i am from argentine.
    I have this XML:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <arrayOfServicio >
        <Servicio>
            <Nombre>Autenticacion</Nombre>
            <Descripcion>ws</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>RequestTicket</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Consultas</Nombre>
            <Descripcion>wsConsultas</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetVigencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetSiniestralidad</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetAgrupados</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetSiniestralidadPorCuil</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Referencias</Nombre>
            <Descripcion>wsReferencias</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>TablaReferencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>ListadoReferencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>General</Nombre>
            <Descripcion>WsGeneral</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetServicios</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>eServicios</Nombre>
            <Descripcion>wseServicios</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>SetComunicacion</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>VentanillaART</Nombre>
            <Descripcion>wsVentanillaART</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>ObtenerNovedades</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Establecimientos</Nombre>
            <Descripcion>wsEstablecimiento</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetConsultaPorCuit</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
    </arrayOfServicio>
    I am working in ORACLE 9.2 and i wrote this query but the result is not correct, i need to join HEAD and DETAIL in some way but cannot do that...
      select extractvalue(value(head),'//Servicio/Nombre/text()') ,
            extractvalue(value(head),'//Servicio/Descripcion/text()'),
            extractvalue(value(head),'//Servicio/Activo/text()'),
            extractvalue(value(head),'//Servicio/Version/text()')
            ,extractvalue(value(detail),'//Metodo/Nombre/text()')
            ,extractvalue(value(detail),'//Metodo/Activo/text()')
            ,extractvalue(value(detail),'//Metodo/Version/text()')
      from arwt_ws_return x
          , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio'))) head
          , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio/MetodosEntity/Metodo'))) detail;
    Ii really appreciate your help.
    Thanks!

    Hi,
    You can do that by passing the head element to the second XMLSequence. That way you maintain the correlation between the parent and its children :
    select extractvalue(value(head), '/Servicio/Nombre') as srv_nombre
         , extractvalue(value(head), '/Servicio/Descripcion') as srv_desc
         , extractvalue(value(head), '/Servicio/Activo') as srv_activo
         , extractvalue(value(head), '/Servicio/Version') as srv_version
         , extractvalue(value(detail), '/Metodo/Nombre') as met_nombre
         , extractvalue(value(detail), '/Metodo/Activo') as met_activo
         , extractvalue(value(detail), '/Metodo/Version') as met_version
    from arwt_ws_return x
       , table(xmlsequence(extract(x.x_xmldoc, '/arrayOfServicio/Servicio'))) head
       , table(xmlsequence(extract(value(head), '/Servicio/MetodosEntity/Metodo'))) detail
    Please also note that :
    - you don't need a descendant axis (//) if you know the exact path
    - you don't need to go down to the text() node if you're using extractvalue
    Hope that helps.

  • Populate header and detail

    Hi,
    I have an internal table with the value below. I need to populate to header data line (1 record only)  and detail is an internal table
    When there is a change of customer, i need to copy 123 to header and 2 records of material (abc & xed), sales (100 & 200) and qty (10 & 12) to detail internal table.
    for customer 567, i need to copy to header and material aqs, sales 150 and qty 5 to detail internal table.
    May I know how can I achieve this?
    customer     material        sales      qty
    123              abc              100         10
    123              xed              200          12
    567              aqs              150           5
    877              abc               140         8
    Thanks
    Rgds

    Hello,
    As per my understanding, your requirement is that you have an internal table which has a combined data and you want to split it into headr and detail internal tables, based on the change of the customer number which is the first field in the combined internal table. If so then assume that it_com is the combined internal table and it_head and it_det as the header and detail interbnal tables respectively.
    First sor the combined internal table on customer number
    sort it_com by kunnr.
    Now loop across this table and on the event at new customer populate the header table and in the remaining loop populate the detail table.
    loop at it_com into wa_com.
      at new kunnr.
         wa_head-kunnr = wa_com-kunnr.
         append wa_head-kunnr to it_head-kunnr.
         clear wa_head-kunnr.
      endat.
    append the records from the combined table into the item table, whatever fields required
    endloop.
    Regards,
    Sachin

  • DMEE issue in header and detail record

    Hi Gurs,
    I am working in DMME payment medium .
    I have declared DMEE  header structure(00000001000001 ) as level 1 and detail (050000010020192             XX110000001) as also level 1.
    This is the output format i am getting.
    00000001000001                                                                               
    05000001002000             XX110000001                                                                               
    00000001000001                                                                               
    05000001002012            XX110000002                                                                               
    00000001000001                                                                               
    05000001002012             XX110000003                                                                00000001000001                                                                               
    05000001002011             XX110000004           
    But my requirment not lke this. i need to dispaly all detail items under one header also i need to increase the counter for every items starting from 2.
    Both header and detail are at  level 1.If i declared the detail as level 2 the output is not generated.
    This is what i need.                                                                               
    00000001000001                                                                               
    05000002002000             XXX110000001                                                        
    05000003002012             XXX110000002
    05000004002012             XXX110000003
    05000005002011             XXX110000004 
    Pls suggest me any solutions
    Thanks .

    NOT answered

  • DMEE Issues header and detail record

    Hi Gurs,
    I am working in DMME(PAYM) payment medium .
    I have declared DMEE header structure(00000001000001 ) as level 1 and detail (050000010020192 XX110000001) as also level 1.
    This is the output format i am getting.
    00000001000001
    05000001002000 XX110000001
    00000001000001
    05000001002012 XX110000002
    00000001000001
    05000001002012 XX110000003 00000001000001
    05000001002011 XX110000004
    But my requirment not lke this. i need to dispaly all detail items under one header also i need to increase the counter for every items starting from 2.
    Both header and detail are at level 1.If i declared the detail as level 2 the output is not generated.
    This is what i need.
    00000001000001
    05000002002000 XXX110000001
    05000003002012 XXX110000002
    05000004002012 XXX110000003
    05000005002011 XXX110000004
    Pls suggest me any solutions
    Thanks .
    Edited by: bala chandran on Oct 9, 2009 10:57 AM

    NOT answered

  • Pivot with header and details

    I need to display data from both header and detail, details has to come from other table also
    --CREATE TABLE
    CREATE TABLE [dbo].[Table_Dept](
    [DeptId] [int] NULL,
    [DeptCode] [char](2) NULL,
    [DeptName] [nvarchar](100) NULL
    ) ON [PRIMARY]
    CREATE TABLE [dbo].[Table_Detail](
    [Header_ID] [int] NOT NULL,
    [Name] [nvarchar](50) NOT NULL,
    [DescValue] [nvarchar](max) NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    CREATE TABLE [dbo].[Table_Header](
    [Header_Id] [int] NULL,
    [UserName] [nvarchar](50) NULL
    ) ON [PRIMARY]
    --INSERT DATA
    INSERT INTO Table_Dept (DeptId, DeptCode, DeptName)
    VALUES (1, 'HO', N'Head Office'),
    (2, 'BO', N'Branch Office'),
    (3, 'RO', N'Reginal Office'),
    (4, 'SO', N'Sub Division Office')
    INSERT INTO Table_Header
    (Header_Id, UserName)
    VALUES (1, N'Ravi'), (2, N'Gopal'), (3, N'Deepa')
    INSERT INTO Table_Detail
    (Header_ID, Name, DescValue)
    VALUES (1, N'ListNumber', N'1005'),
    (1, N'PhaseCode', N'AA'),
    (1, N'DeptCode', 'BO,RO'),
    (1, N'City', 'Bangalore'),
    (2, N'ListNumber', N'1006'),
    (2, N'PhaseCode', N'AB'),
    (2, N'DeptCode', 'SO,RO'),
    (2, N'City', 'Delhi'),
    (3, N'ListNumber', N'1007'),
    (3, N'PhaseCode', N'AA'),
    (3, N'DeptCode', 'HO'),
    (3, N'City', 'Mumbai')
    --EXPECTED RESULT
    HeaderId
    ListNumber
    PhaseCode
    DeptName
    City
    User
    1
    1005
    AA
    Branch Office,   Reginal Office
    Bangalore
    Ravi
    2
    1006
    AB
    Sub Division   Office,Reginal Office
    Delhi
    Gopal
    3
    1007
    AA
    HO
    Mumbai
    Deepa
    ShanmugaRaj

    see below code
    SELECT *,
    STUFF((SELECT ',' + DeptName
    FROM Table_Dept
    WHERE ',' + t.DeptCode + ',' LIKE '%,' + DeptCode + ',%'
    FOR XML PATH('')),1,1,'') AS DeptName
    FROM
    SELECT h.Header_ID,
    td.ListNumber,
    td.PhaseCode,
    td.DeptCode,
    td.City
    FROM Table_header h
    INNER JOIN (SELECT Header_ID,
    MAX(CASE WHEN Name = 'ListNumber' THEN DescValue END) AS ListNumber,
    MAX(CASE WHEN Name = 'PhaseCode' THEN DescValue END) AS PhaseCode,
    MAX(CASE WHEN Name = 'DeptCode' THEN DescValue END) AS DeptCode,
    MAX(CASE WHEN Name = 'City' THEN DescValue END) AS City
    FROM Table_Detail
    GROUP BY Header_ID)td
    ON td.Header_ID = h.Header_ID
    )t
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    In case of not having department table...consider the dept code, where the values are now comming from table and
    need result if the data is not displayed from table and they are static..
    use case when 'Bo' then 'Branch Office'
    when 'Ro' then 'Reginal Office'
    when 'So' then 'Sub Division Office'
    when 'Ho' then 'Head Office'
    kindly suggest how to replace my above query
    ShanmugaRaj

  • 11i AP Different Liability Accounts at invoice header and supplier pay site

    Hi
    Noticed that Liab Acct at Invoice header and supplier pay site is different and not the same.
    How this is possible?
    need help
    SS

    Hi,
    While entering the invoice you can change the liability account on invoice header, if the filed is not displayed check in folder options (folder->show Field->Liability Account)
    Thanks,
    Vijay

  • How to execute .sql file in Stored Procedure?

    Hi,
    I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
    This .sql file will have set of update statement. I need to pass value to this update statement.
    Kindly please help me.
    Regards,
    Irfan

    This is required as part of Data Migration where  i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
    How have you determined that it's "better" to have seperate scripts?  I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
    So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
    Question: Why do you have tables with different names that all need the same process doing to them?
    Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
    e.g.
    create procedure update_table(tbl_name varchar2) is
    begin
      execute immediate 'update '||tbl_name||' set lastupdate = null';
    end;
    As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer.  Please do take the time to read the FAQ and post appropriate details so people can help you.

  • Calling SQL * LOADER  in stored procedure

    Hi Experts,
    Can we call sql*loader in stored procedures? . If yes , please let me know the syntax.
    Any help will be highly appreciated.
    Thanks.

    You can also use dbms_schedular to execute any shell or batch file - i guess ->
    BEGIN
      -- UNIX
      DBMS_SCHEDULER.create_job(
        job_name             => 'unix_command_job',
        job_type             => 'EXECUTABLE',
        number_of_arguments  => 1,
        job_action           => '/bin/ls',
        auto_drop            => FALSE,
        enabled              => FALSE);
      DBMS_SCHEDULER.set_job_argument_value('unix_command_job',1,'/tmp');
      DBMS_SCHEDULER.set_attribute('unix_command_job', 'credential_name', 'TIM_HALL_CREDENTIAL');
      DBMS_SCHEDULER.set_attribute('unix_command_job', 'destination', 'marge.localdomain:65001');
      DBMS_SCHEDULER.enable('unix_command_job');
    END;For details ->
    http://www.oracle-base.com/articles/11g/SchedulerEnhancements_11gR1.php
    http://www.oradev.com/dbms_scheduler.jsp
    http://www.psoug.org/reference/dbms_scheduler.html
    Regards.
    Satyaki De.

  • .sql program VS stored procedure

    Hi,
    We are in the process of migrating a lot of .sql files into Oracle warehouse Builder programs.
    So most of them will be converted to stoted procedure, Before committing anything , Just a quick question ..
    Can there be any statements which is ONLY possible in .SQL files (OS level files)
    and which is NOT possible in Stored procedure ?
    cheers
    Ranjeesh

    Depends on what kind of code you have in those SQL-script files.
    SQL*Plus commands cannot be used in PL/SQL procedure, e.g. COLUMN-formatting, environment SETting, and BREAK etc.
    There should not be any problem with converting DMLs. But, in case of DDLs you will have to use dynamic PL/SQL.

  • What is the data dictionary that stores the SQL text of stored procedures?

    I am handling both Oracle 8i on IBM AIX 5L and Oracle9i on SUN Soliars 8 /9.
    What is/are the data dictionary tables, or v$ views that store the SQL text of stored procedured and triggers?
    Thank you in advance!

    If the procedures are not wrapped, you can view them in the dba/all/user_source view. Trigger bodies can be seen in dba/all/user_triggers view.
    Message was edited by:
    Daniel Fink

  • Returning SQL cursor from Stored Procedure

    Hi,
    I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
    I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
    assume both query returns equal number of rows.. however both are not related to each other..

    RP wrote:
    Hi,
    I have a query regarding returning sql cursor from stored procedure to java in oracle 11g.
    I want to query some data ex: my query returns A, B, C. Also, now I want to query some other data ex: D, E, F. Now I want to return this data as an sql cursor as a single row . Example: A,B,C,D,E,F. Is it possible to return/create a cursor in stored procedure?
    assume both query returns equal number of rows.. however both are not related to each other..It sounds like what you need is a ref cursor.
    First thing to remember though is that cursors do not hold any data (see: {thread:id=886365})
    In it's simplest form you would be creating a procedure along these lines...
    SQL> create or replace procedure get_data(p_sql in varchar2, p_rc out sys_refcursor) is
      2  begin
      3    open p_rc for p_sql;
      4  end;
      5  /
    Procedure created.
    SQL> var rc refcursor;
    SQL> exec get_data('select empno, ename, deptno from emp', :rc);
    PL/SQL procedure successfully completed.
    SQL> print rc;
         EMPNO ENAME          DEPTNO
          7369 SMITH              20
          7499 ALLEN              30
          7521 WARD               30
          7566 JONES              20
          7654 MARTIN             30
          7698 BLAKE              30
          7782 CLARK              10
          7788 SCOTT              20
          7839 KING               10
          7844 TURNER             30
          7876 ADAMS              20
          7900 JAMES              30
          7902 FORD               20
          7934 MILLER             10
    14 rows selected.
    SQL> exec get_data('select deptno, dname from dept', :rc);
    PL/SQL procedure successfully completed.
    SQL> print rc
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
            40 OPERATIONS
            50 IT SUPPORTWhich takes an SQL statement (as you said that both your queries were unrelated), and returns a ref cursor, and then your Java code would fetch the data using that cursor.
    Now, as for getting your rows to columns and combining two queries that do that... something along these lines...
    SQL> select * from x;
    C
    A
    B
    C
    SQL> select * from y;
    C
    D
    E
    F
    SQL> ed
    Wrote file afiedt.buf
      1  select x.col1, x.col2, x.col3
      2        ,y.col1 as col4
      3        ,y.col2 as col5
      4        ,y.col3 as col6
      5  from (
      6        select max(decode(rn,1,col1)) as col1
      7              ,max(decode(rn,2,col1)) as col2
      8              ,max(decode(rn,3,col1)) as col3
      9        from (select col1, rownum rn from (select * from x order by col1))
    10       ) x
    11  cross join
    12       (
    13        select max(decode(rn,1,col1)) as col1
    14              ,max(decode(rn,2,col1)) as col2
    15              ,max(decode(rn,3,col1)) as col3
    16        from (select col1, rownum rn from (select * from y order by col1))
    17*      ) y
    SQL> /
    C C C C C C
    A B C D E F... will do what you ask. For further information about turning rows to columns read the FAQ: {message:id=9360005}

  • Requirements of SQL Server 2005 Stored Procedures to Develop Crystal Report

    Hi All,
       I want to learn how to create crystal report off of SQL Server 2005 Stored Procedure. So anybody please let me know from where I can download the documentation on "Requirements of SQL Server 2005 Stored Procedures for crystal report.
      I am using Crystal Report XI. Any help is greatly appreciated.
    Thank You.

    Hello,
    When CR uses Stored Porcedures we only look at the last SELECT statement. We can't use TMP tables because they are owned by the system and not the user. Even though you created them under your logon credentials you are not the actual owner. Or so I have found so far.... CR does not have permissions to get to those temp tables. If you can find out dynamically what the table names are called then it may work. I don't have a sample but it has the usual table info with a random GUID or temp name, really long, and changes every time.
    What should work is create a real table, not one of MS's tempTables and then push all your data to that table and then the last select statement returns all of your data from that temp table:
    SELECT * FROM MYTEMPTABLE.DBO.TABLE.
    Then CR should ahve no issues.
    It may be that the JDBC driver has problems. Test it using OLE DB or ODBC.
    Thanks again
    Don

Maybe you are looking for

  • Tree no longer showing in 4.1...unsure of how to debug

    we recently updated apex from 4.0 to 4.1. When we did this, our TREE stopped working. This is code written by someone else and I am unfamiliar with javascript, but I was wondering if there is something in particular that I should look for. The tree w

  • Exporting file to Youtube Elements 7

    Hi Guy's, I'm tring to help someone else so i dusted off my elements 7 software and I'm have a problem exporting the video. The file size is 96 megs.How can I comprise the file? I tried the "share" Internet" options to post...but the youtube option i

  • XSL Transformation error source

    I am using MII 12.0 and I am getting the following error in the log file: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sap.engine.services.servlets_jsp.server.exceptions.WebIOException: An attempt to write a

  • FTP: File receiver cc error...Looks pretty simple...Can U solve this

    Hello all,    I have a simple scenario of sending the file from shared directory to FTP. When I execute the sceanrio..sender is picking up the file ..No issues in SXMB_MONI...but when I checked in the message monitoring...at adapter level for file re

  • How to run the processRequest initialization only once

    My home page has a table that is initially populated based on the users userId. The user can then select a differnt user to display data for. From the table, the user can drill down to another page. If the user uses the browser back button (need to p