Help:Oracle 9i Active database trigger for insert

Pract 4:Active Databases
Create a table emp1 (eno, ename, hrs, pno, super_no) and
project (pname, pno, thrs, head_no) where
thrs is the total hours and is the derived attribute.
Its value is the sum of the hrs of all employees working
on that project, eno and pno are primary keys,
head_no is the foreign key to emp relation.
Insert 10 tuples and write triggers to do the following
1) Creating a trigger to insert a new employee tuple and
display the new total hours from project table.
2) Creating a trigger to change the hrs of
existing employee and display the new      total hrs from project table
3) Creating a trigger to change the project of an employee and
display the new total hrs from project table
4) Creating a trigger to deleting the project of an employee
--using bom1:-
SQL> connect hr/tiger@bom4;
Connected.
SQL> create table Project17
2 (
3 pno number(5) primary key,
4 pname varchar2(25),
5 thrs number(5),
6 head_no number(5)
7 );
Table created.
SQL> create table Emp17
2 (
3 eno number(5) primary key,
4 ename varchar2(25),
5 hrs number(5),
6 pno number(5),
7 super_no number(5),
8 constraint Pno_fk foreign key(pno) references Project17(pno)
9 );
Table created.
--Inserting records into table Emp1
SQL> insert into Project17 values(1,'IMS',125,1);
1 row created.
SQL> insert into Project17 values(2,'CRM',135,1);
1 row created.
SQL> insert into Project17 values(3,'P and A Section',145,2);
1 row created.
SQL> insert into Project17 values(4,'Rishabh Dighia Steels',225,3);
1 row created.
SQL> insert into Project17 values(5,'BPTLibrary',215,4);
1 row created.
--Inserting records into table Project
SQL> insert into Emp17 values(3,'Shubhangi',145,3,28);
1 row created.
SQL> insert into Emp17 values(4,'Crima',225,2,98);
1 row created.
SQL> insert into Emp17 values(5,'Harshada',215,4,62);
1 row created.
SQL> insert into Emp17 values(6,'ashish',215,4,62);
1 row created.
SQL> insert into Emp17 values(7,'salil',115,3,92);
1 row created.
                    Queries:-
connect hr/tiger@bom4;
1) Create a trigger to insert a new emp tuple and display the new total hrs
from project table
create or replace trigger trigemp_ins
after insert on Emp17
for each row
when(new.pno is not null)
declare
vthrs number(9);
begin
insert into Project17 values(:new.pno,pname,thrs,head_no);
Select thrs into vthrs from Project17 where pno=:new.pno and thrs=thrs+:new.hrs;
dbms_output.put_line('new Total Hrs:'||vthrs);
end;
Warning: Trigger created with compilation errors.
SQL> show errors;
Errors for TRIGGER TRIGEMP_INS:
LINE/COL ERROR
4/2 PL/SQL: SQL Statement ignored
4/51 PL/SQL: ORA-00984: column not allowed here

Hi,
have a look at your insert. It misses some ":new."
Herald ten Dam
Superconsult.nl

Similar Messages

  • Help me in creating a Trigger for Insert and Update Options

    Hi
    Please help me in creating a Trigger .
    My requirement is that after insert or update on a Table , i want to fire an event .
    I have started this way ,but doesn't know how to fully implement this .
    say i have a dept table
    CREATE TRIGGER DepartmentTrigger
    AFTER INSERT ON Dept
    BEGIN
    INSERT INTO mytable VALUES("123","Kiran");
    END DepartmentTrigger;
    Please tell me how can i put the Update option also .
    Thanks in advance .

    Please tell me how can i put the Update option also .Add "Or Update". ;-)
    Here are a few suggestions, but you definitely need to refer to the manual page that the previous poster suggested.
    CREATE OR REPLACE TRIGGER DepartmentTrigger
    AFTER INSERT Or Update ON Dept
    BEGIN
    INSERT INTO mytable VALUES(:new.Dept,'DEPT ADDED OR CHANGED');
    END DepartmentTrigger;
    The "Or Replace" means you can replace the trigger while you're developing without having to type in a drop statement every time. Just change and rerun your script, over and over until you get it right.
    Adding "Or Update" or "Or Delete" makes the trigger fire for those events too. Note, you may want seperate triggers in different scripts and with different names for each event. You have to decide if your design really does the same thing whether it's an insert or an update.
    :new.Dept is how you would refer to the changed vale of the Dept column (:old.Dept is the prior value). I changed the double quotes on the string in the VALUES clause to single quotes.
    Andy

  • How to Create a table with numeric trigger for INSERT

    Let me start off by saying that I am very new to DBMS.
    I need to create a Table with INSERT Trigger. I am not exactly sure if I need to have a BEFORE ot AFTER insert trigger but leanning towards AFTER.
    I have a Java code that will need insert a row each time that piece of code is executed. I would also like an oracle trigger to insert a unique numeric value (REC_ID) for that that record.
    I am totally lost and I am not sure how to go about it. Can you point me to the right direction?
    Basically my table will have the following 3 columns
    REC_ID NUMBER NOT NULL (uniquie value inserted by the trigger)
    PROPERTY_NAME VARCHAR2(100 BYTE)
    PROPERTY_VAL VARCHAR2(100 BYTE)
    Thank you in advance
    Eric

    Take a look at the following: Also please do a search in this forum.
    http://infolab.stanford.edu/~ullman/fcdb/oracle/or-jdbc.html

  • How to Pass APP_USER to a database trigger for auditing

    I have a table which is updated by an Apex Page. (Application Express 4.2.1.00.08).
    The application is using the standard Oracle apex authentication.
    I have created an Audit table with a before update trigger to insert a record into the audit table of who made a change to what column and when.
    If I use User in the trigger I get APEX_PUBLIC_USER recorded as who changed the record.
    What I actually need is the APP_USER Value e.g KJR recorded. I am not writing the APP_USER to a field in the table so I cannot use : new syntax to capture it from any of the field I am updating.
    Can anyone advise how I can pass the APP_USER for the trigger to use?

    In PL/SQL code like Trigger you can access the value of item by using v function. Refer the below link
    http://docs.oracle.com/cd/E1755601/doc/user.40/e15517/concept.htm#BEICHBBG_
    You can use NVL function as well,
    :NEW.CREATED_BY := NVL(v('APP_USER'), USER);Thanks,
    Lakshmi

  • Issue in Database trigger for HZ_CUSTOMER_PROFILES PL/SQL: ORA-00936: miss

    Hi
    We are trying to create database trigger on update of table HZ_CUSTOMER_PROFILES when CREDIT_HOLD='Y'
    If this update is done from certain operating unit we are inserting into another custom table when compiling trigger we are getting error as given below
    LINE/COL ERROR
    5/2 PL/SQL: SQL Statement ignored
    17/2 PL/SQL: ORA-00936: missing expression
    SQL> l 5
    5*
    SQL> l 17
    17* COUNTRY,
    Copying code used for creating trigger
    CREATE OR REPLACE TRIGGER "APPS"."SDS_CREDIT_HOLD_ROW"
    BEFORE UPDATE ON HZ_CUSTOMER_PROFILES
    FOR EACH ROW
    WHEN ( new.CREDIT_HOLD='Y')
    BEGIN
    IF FND_PROFILE.VALUE('ORG_ID')=3217 THEN
    INSERT INTO SDS.SDS_CREDIT_HOLD
    (CUSTOMER_NAME,
    CUSTOMER_NUMBER,
    ADDRESS,
    CITY,
    COUNTRY,
    HOLD_BY,
    MAIL_LIST1,
    RESP_VALUE,
    ORG_ID,
    MAIL_LIST2)
    VALUES
    (select rc.customer_name,
    rc.customer_number,
    ra.address1,
    ra.city,
    ra.country,
    fu.user_name,
    fu.email_address,
    TO_NUMBER(FND_GLOBAL.RESP_ID),
    TO_NUMBER(fnd_profile.value('ORG_ID')),
    SDS_EMAIL_ADD_FNC('KAMALAKAR.GUDAPAREDDI,BRIAN.MILLER')
    from HZ_CUSTOMER_PROFILES hcp, ra_site_uses rsa,
    ra_addresses ra, ra_customers rc, fnd_user fu,
    (select distinct site_use_id from HZ_CUST_SITE_USES where site_use_code='BILL_TO'
    and status='A') site_acct
    where hcp.status='A'
    and cust_account_id in (select distinct cust_account_id from HZ_CUSTOMER_PROFILES
    where credit_hold='Y'
    and status='A')
    and hcp.site_use_id=rsa.site_use_id (+)
    and rsa.address_id=ra.address_id (+)
    and rsa.site_use_id= site_acct.site_use_id (+)
    and hcp.cust_Account_id=rc.customer_id
    and hcp.credit_hold='Y'
    and hcp.last_updated_by=fu.user_id
    and hcp.CUST_ACCOUNT_PROFILE_ID=:new.CUST_ACCOUNT_PROFILE_ID
    and hcp.ROWID=:new.ROWID);
    END IF;
    -- commit;
    END SDS_CREDIT_HOLD_ROW;
    tried to search for fix in forums checked all columns in select clause and insert they appear to be fine attaching table structure also for reference
    CREATE TABLE SDS_CREDIT_HOLD
    (CUSTOMER_NAME VARCHAR(50),
    CUSTOMER_NUMBER VARCHAR2(30),
    ADDRESS VARCHAR2(240),
    CITY VARCHAR2(60),
    COUNTRY VARCHAR2(60),
    HOLD_BY VARCHAR2(100),
    MAIL_LIST1 VARCHAR2(240),
    RESP_VALUE NUMBER,
    ORG_ID NUMBER,
    MAIL_LIST2 VARCHAR2(240))
    if any hint for fixing this issue it will be highly appreciated
    Thanks
    Kamalakar.G

    Problem is here:
    WHEN ( new.CREDIT_HOLD='Y')
    Should be using a colon in front of any new or old columns in your PL/SQL and SQL, thus try this:
    WHEN ( :new.CREDIT_HOLD='Y')
    FYI: when using triggers (unless you specify otherwise in the trigger definition itself):
    old values are referenced via :old.column and new values via :new.column

  • Trigger for insert in other table

    hi im merwyn and im new in JDBC
    my problem is i want to insert the values from one table to another immediately the value is inserted in first table
    my first table defination is
    create table ItemEJBTable
         ( itemCode int primary key,
         itemDescription varchar (50),
         quantityOnHand varchar(50),
         rate varchar(50),
         releaseDate varchar(50),
         singer varchar (50),
         title varchar (50),
         type varchar (50)
    )and other table
    create table Item_Master
         ( Item_Code int primary key,
         Item_Desc varchar (50),
         Qty_on_hand varchar(50),
         Rate varchar(50),
         Release_Date varchar(50),
         Singer varchar (50),
         Title varchar (50),
         Type varchar (50)
    )i have also done trigger
    create trigger EJBtoItem
    on ItemEJBTable for insert as
    BEGIN
    INSERT into Item_Master(Item_Code,Item_Desc,Qty_on_hand,Rate,Release_Date,Singer,Title,Type)
    VALUES(new.itemCode,new.itemDescription,new.quantityOnHand,new.rate,new.releaseDate,new.singer,new.title,new.type)
    PRINT 'Successful'
    ENDbut SQL2000 gives me this error
    The name 'itemCode' is not permitted in this context.
    Only constants, expressions, or variables allowed here.
    Column names are not permitted.what is the solution of this????
    sorry if i posted in wrong section but im adding the values to table throught jsp page
    pls help
    Edited by: merwyn on Mar 14, 2009 10:52 PM

    Note: This thread was originally posted in the [Java Servlet |http://forums.sun.com/forum.jspa?forumID=33] forum, but moved to this forum for closer topic alignment.

  • How to create a database trigger for automatic run statspack.snap

    Hi,
    I want to create a database trigger to run statspack.snap at startup.
    connect /as sysdba
    grant create any trigger to perfstat;
    connect perfstat/perfstat
    create or replace trigger auto_snap
    after startup on database
    begin
    statspack.snap;
    end;
    after startup on database
    error at line 2:
    ora-01031: insufficient privileges
    connect /as sysdba
    create or replace trigger perfstat.auto_snap
    after startup on database
    begin
    statspack.snap;
    end;
    Trigger created.
    after shutdown and startup the database, the trigger has not been run. (no statspack snapshot)
    What I have done wrong?

    981145 wrote:
    hi... I have created a database link but it is showing some error. Can you please tell me, do we have to update the details in TNSNAMES.ora file regarding the database which i am creating now before creating database link?????
    awaiting for your response,
    Thanks in advanceI'm sorry, but "showing some error" is NOT an actionable error message. Why do you think we can solve your error if you don't tell us what the error is?
    Yes you will need to adjust your tnsnames. When a process in a database_A accesses database_B via a dblink in database_A, the database_A is acting as a client to database_B. At that point database_A is just like sqlplus or sqldeveloper, and all tns considerations are the same.

  • Oracle 11g R2 Database Client for Mac OS X?

    Is there an Oracle 11g R2 client for Mac OS X? If so, where is it?

    Hi;
    Please check:
    http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
    Also see:
    Master Note For Oracle Database Client Installation [ID 1157463.1]
    Client / Server / Interoperability Support Between Different Oracle Versions [ID 207303.1]
    Master Note For Database and Client Certification [ID 1298096.1]
    Regard
    Helios

  • Database trigger to insert duplicated rows on audit table

    Hi
    It is possible to insert duplicate rows (at the moment database generate PK violation constraint for one specific table) within an audit table ?
    Certain code like this is not working, always the whole transaction makes a rollback and audit table will be empty:
    CREATE OR REPLACE TRIGGER USER.audit_TABLE_TRG
    before INSERT ON USER.TABLE
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    declare
    V_conteo number(1) := 0;
    duplicate_record EXCEPTION;
    begin
    select count(*)
    into V_conteo
    from USER.TABLE
    where <PK conditions>
    if V_conteo > 0 then
    begin
    INSERT INTO USER.AUDIT_TABLE
    (<>)
    VALUES
    (<>);
    raise duplicate_record;
    exception
    when duplicate_record then
    INSERT INTO USER.AUDIT_TABLE
    (<>)
    VALUES
    (<>);
    raise_application_error(-20019,'Duplicated column1/column2:'||:NEW.column1||'/'||:NEW.column2);
    when others then
    dbms_output.put_line('Error ...'||sqlerrm);
    end;
    end if;
    end;
    END;
    /

    >
    Exactly this is my problem , one only transaction (insert into audit table and try to insert into target table), the reason of this post is to know whether exists another way to insert all the intent duplicate records on target table into one audit table, you right ,maybe I can add one date column and modify the PK on audit table but my main problem still happens.
    >
    Can I ask you why you want to go trigger route for this if your intention is only to capture the duplicate records? Assuming that you are on at least on 10gR2, you can look at DML error table. If you go this route, there is no need for additional overhead of trigger, code failures, etc.
    Oracle can automatically store the failed records in an error table which you could later on investigate and fix it or ignore it.
    Simple example:
    SQL> create table emp (empno number primary key, ename varchar2(10), sal number);
    Table created.
    SQL> insert into emp values(1010, 'Venkat', 100);
    1 row created.
    SQL> commit;
    Commit complete.
    Create error table to log the failed records
    BEGIN
          DBMS_ERRLOG.create_error_log (dml_table_name => 'emp');
    END;
    Now let's insert a duplicate record
    SQL> insert into emp values(1010, 'John', 200) ;
    insert into emp values(1010, 'John', 200)
    ERROR at line 1:
    ORA-00001: unique constraint (VENKATB.SYS_C002813299) violated
    Now use the log table to capture
    SQL> insert into emp values(1010, 'John', 200) LOG ERRORS INTO err$_emp ('INSERT') REJECT LIMIT UNLIMITED;
    0 rows created.
    Now check the error log table and do whatever you want
    SQL> r
      1* select ORA_ERR_MESG$, empno, ename, sal from err$_EMP
    ORA_ERR_MESG$
    EMPNO
    ENAME
    SAL
    ORA-00001: unique constraint (VENKATB.SYS_C00
    2813467) violated
    1010
    John
    200
    1 row selected.This will also capture when you do
    INSERT INTO EMP SELECT * FROM EMP_STAGE LOG ERRORS INTO err$_emp ('INSERT') REJECT LIMIT UNLIMITED;
    You can capture the whole record into the log table. All columns.
    Regards
    Edited : Code

  • Plz.. Help me to get  database field for Rate/Hour

    I have  the requirement to get  the Rate/Hour for Actual Labor ,OT Labor and WE Labor etc.
    <b>I am passing  Activity types to AFVC-LARNT to get different types of Labor</b> .But i don't know the Database Table Field to get this Rate/Hour .
    please suggest me from which table i have to pick Rate/Hour .Please specify the Field Name also.
    <b>If it is from AFVC please suggest me the  Field Name for RATE/HOUR .
    Input is AUFK-AUFNR. </b>
    Rewards
    Anu.

    Hi
    Activity Hours take from AFVV table passing AUFNR field of AFKO tables
    Activity costs are to be taken from COST table by passing the OBJNR field  which is combination of <KL><Controlling area><Cost center><Activity Type>
    Take this fields related to AUFNR and pass from AUFK or AFKO..
    Regards
    Anji

  • Is Oracle still actively creating AMIs for Oracle Linux?

    Hi All,
    I was wondering if any of you knows if Oracle is still actively creating new Oracle Linux AMIs for Amazon EC2? I can see the most recent one is Oracle Linux 6.1 while we are already at 6.3.
    Now that Oracle has announced they are in the IaaS and PaaS business as well, do they stop supplying Amazon AMIs?
    Bart.

    I would never deploy the first point release of a major release into production. In my experience, Oracle rolls out 2 "releases" of each major version. The SECOND release tends to be production-ready for shops with serious HA requirements. Usually, this Second release also contains sneak previews of the important features of the next major Version--but these should be considered version 1.0 features and not relied upon. The FIRST release of a major version will contain those important features in a strong form suitable for the vast majority of shops--but it will still have lots of bugs. If you have to bounce your instance even once a month to work around a bug, you aren't getting close to HA.
    My advice--the most stable version will always be the terminal release of the last version--currently 9.2.0.6. Similarly, the last point release of R1 will be quite stable. Realistically, 98% of the customer base can live with occasional downtime and bug problems, and will enjoy the new features of the latest software. Even for them, I'd wait for the second point release or higher for production. QA and DEV are different stories--jump on the latest wave and write code using the newest features. But wait for the second point release before going into production. Typically it will be out in a few months and will fix the glaring bugs.

  • Help: Oracle 9i Replication Trigger

    Create a global conceptual schema Emp(Eno;Ename;Address;Email;Salary) and insert 10
    records.Store the replication of Emp into two different nodes And
    fire the following queries :
    1)Find the salary of all employees.
    2)Find the email of all employees where salary = 15000.
    3)Find the employee name and email where employee number is known.
    4)Find the employee name and address where employee number is known.
    SQL> connect hr/tiger@bom6 as sysdba;
    Connected.
    SQL> create public database link link2bom64 connect to hr identified by tiger using 'bom4';
    Database link created.
    SQL> commit;
    Commit complete.
    SQL> connect hr/tiger@bom5 as sysdba;
    SQL> create public database link link2bom54 connect to hr identified by tiger using 'bom4';
    Database link created.
    SQL> commit;
    Commit complete.
    SQL> connect hr/tiger@bom4 as sysdba;
    Connected.
    SQL> create public database link link2bom45 connect to hr identified by tiger using 'bom5';
    Database link created.
    SQL> commit;
    Commit complete.
    SQL> connect hr/tiger@bom6 as sysdba;
    SQL> create public database link link2bom65 connect to hr identified by tiger using 'bom5';
    Database link created.
    SQL> commit;
    Commit complete.
    SQL> connect hr/tiger@bom4 as sysdba;
    Connected.
    SQL> create public database link link2bom46 connect to hr identified by tiger using 'bom6';
    Database link created.
    SQL> commit;
    Commit complete.
    SQL> connect hr/tiger@bom5 as sysdba;
    SQL> create public database link link2bom56 connect to hr identified by tiger using 'bom6';
    Database link created.
    SQL> commit;
    Commit complete.
                   Global Database at bom4:-
    SQL> connect hr/tiger@bom4;
    Connected.
    SQL> create table Emp_Replica
    Eno number(5),
    Ename varchar2(25),
    Address varchar2(25),
    Email varchar2(30),
    Salary number(5)
    Table created.
                   Creating database at bom5:-
    SQL> connect hr/tiger@bom5;
    Connected.
    SQL> create table Emp7 as(Select * from Emp_Replica@link2bom54);
    Table created.
                   Creating database at bom3:-
    SQL> connect hr/tiger@bom6;
    Connected.
    SQL> create table emp8 as(Select * from Emp_Replica@link2bom64);
    Table created.
                   Creating Trigger For Inserting REcords:-
    create or replace trigger trigg_ins
    after insert on Emp_Replica
    for each row
    begin
    insert into Emp7@link2bom45 values
    (:old.eno,:old.ename,:old.address,:old.email,:old.salary);
    end;
    create or replace trigger trigg_ins2
    after insert on Emp_Replica
    for each row
    begin
    insert into Emp8@link2bom46 values
    (:old.eno,:old.ename,:old.address,:old.email,:old.salary);
    end;
    SQL> insert into Emp_Replica values(&eno,'&ename','&address','&email',&salary);
    Enter value for eno: 1
    Enter value for ename: niket
    Enter value for address: andheri
    Enter value for email: [email protected]
    Enter value for salary: 15000
    old 1: insert into Emp_Replica values(&eno,'&ename','&address','&email',&salary)
    new 1: insert into Emp_Replica values(1,'niket','andheri','[email protected]',15000)
    insert into Emp_Replica values(1,'niket','andheri','[email protected]',15000)
    ERROR at line 1:
    ORA-04098: trigger 'HR.TRIGEMP_REPLICA_INS' is invalid and failed re-validation
    --on insering into emp_replica it gives trigger invalid and revalidation failed error...please help me to solve this                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    Check the list of triggers which are in invalid state and find whether two or more triggers were created to perform same operation on the very same table. This might result in ORA-04098.
    Drop the unwanted triggers created on the same table and just keep one and try executing the DML again.
    select object_name
    from user_objects
    where object_type = 'TRIGGER'
    and status = 'INVALID';Regards,
    Prazy

  • Print insert result to a printer in TSQL trigger after insert - Need help.

    Hi,
    I am trying to print a record to a printer whenever a new record is inserted into a table called PrintTickets, using TSQL trigger for insert. 
    Is it possible to print a new inserted record to a printer?
    Here is the trigger tsql statement: 
    ALTER TRIGGER [dbo].[PrintDeal]
    ON [dbo].[PrintTickets]
    AFTER INSERT
    AS
    declare @Id numeric(18,0)
    ,@DealId char(15)
    ,@ValueDatePeriod1Currency1 datetime
    ,@Bank1Name char(56)
    ,@Currency1 char(3)
    ,@Currency2 char(3)
    ,@PaymentInstructionP1C1 char(80)
    ,@DealerId char(6)
    ,@DealVolumeCurrency1 float
    ,@CalVolumeP1C2 float
    ,@ExchangeRatePeriod1 float
    declare @tmp table
    Id numeric(18,0)
    ,DealId char(15)
    ,ValueDatePeriod1Currency1 datetime
    ,Bank1Name char(56)
    ,Currency1 char(3)
    ,Currency2 char(3)
    ,PaymentInstructionP1C1 char(80)
    ,DealerId char(6)
    ,DealVolumeCurrency1 float
    ,CalVolumeP1C2 float
    ,ExchangeRatePeriod1 float
    PRIMARY KEY (Id)
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for trigger here
    insert @tmp
    select
    Id
    , DealId
    , ValueDatePeriod1Currency1
    , Bank1Name
    , Currency1
    , Currency2
    , PaymentInstructionP1C1
    , DealerId
    , DealVolumeCurrency1
    , CalVolumeP1C2
    , ExchangeRatePeriod1
    FROM dbo.PrintTickets
    WHERE ID=@@IDENTITY
    select @Id=Id
    ,@DealId=DealId
    ,@ValueDatePeriod1Currency1=ValueDatePeriod1Currency1
    ,@Bank1Name=Bank1Name
    ,@Currency1=Currency1
    ,@Currency2=Currency2
    ,@PaymentInstructionP1C1=PaymentInstructionP1C1
    ,@DealerId=DealerId
    ,@DealVolumeCurrency1=DealVolumeCurrency1
    ,@CalVolumeP1C2=CalVolumeP1C2
    ,@ExchangeRatePeriod1=ExchangeRatePeriod1
    from @tmp
    -- Code to print to a physical printer if possible
    END
    The table is called PrintTickets and it contains the following columns: 
    Id numeric(18,0)
    ,DealId char(15)
    ,ValueDatePeriod1Currency1 datetime
    ,Bank1Name char(56)
    ,Currency1 char(3)
    ,Currency2 char(3)
    ,PaymentInstructionP1C1 char(80)
    ,DealerId char(6)
    ,DealVolumeCurrency1 float
    ,CalVolumeP1C2 float
    ,ExchangeRatePeriod1 float
    PRIMARY KEY (Id)
    The dummy records that I am inserting for testing the results in csv format:
    Id,DealId,ValueDatePeriod1Currency1,Bank1Name,Currency1,Currency2,PaymentInstructionP1C1,DealerId,DealVolumeCurrency1,CalVolumeP1C2,ExchangeRatePeriod1
    696,XXX#33111 ,2014-03-04 00:00:00.000,HSBC ,USD,EUR,XXXXXXXXXXXXXXXXXXXXXXX ,MAT ,342342,87987,0.3123
    697,XXX#33113 ,2014-03-04 00:00:00.000,USB ,EUR,USD,9999999999999999999999,ZXY,2334243,32213,0.3245
    698,XXX#33114 ,2014-03-03 00:00:00.000,SWISS BANK ,CHF,USD,99999999999999900000,XYZ ,32423424,342,0.83432
    699,XXX#33115 ,2014-03-03 00:00:00.000,UK BANK ,USD,PND,XXXXXXXXXXXXXXXXXXXXXXX ,ABC,9809808,0,0.0349
    700,XXX#33116 ,2014-03-04 00:00:00.000,USCF BANK ,XXX,XXX,XXXXXXXXXXXXXXXXXXXXXXX ,ABC,89798797,756756,0.734
    I appreciate any help.
    Thanks in advance.

    Is it possible to print a new inserted record to a printer?
    From SQL Server?
    The task of SQL Server is to manage large of data effciently. It is not a general programming environment. It could possibly be done with a CLR procedure that that talks to the printer, but it is not the correct solution.
    A possible design could be to post a message on a Service Broker queue, and then the printing server would poll the queue and print the ticket.
    By the way, there are more flaws in your trigger. To find the inserted rows, you need to query the virtual table "inserted" which holds a copy of these rows. Furthermore, since a trigger fires once per statement, the trigger must handle the fact
    that multiple rows are inserted.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Oracle form based on a view - need to return a value after database trigger

    We have a form based on a view calling database trigger to insert data.
    I need to display a message of the record ID inserted on the form.
    The values to be displayed are ID field.

    Hi,
    if you use process of Automatic Row Processing (DML), you have an option *"Return Key Into Item"*.
    This will return your primary key into item, and then you can display this item as a result.
    Regards,
    Aljaz

  • Database trigger cannot read the updating table

    I want to create a database trigger :
    after insert or update on EMP
    for each row
    begin
    select sum(EMP.salary) from EMP WHERE .....
    end;
    However, I got an error is that I cannot read the updating table if the trigger is 'for each row'. Can anyone help me to to this?
    More, I must use 'for each row' trigger for this case.
    null

    I think the SQL statement should be
    strSQL = "SELECT * FROM MaterialLotJobJoint WHERE JobID=" & _
    tempvars!JobID & " AND MatLotID=" & tempvars!MatLotID
    This assumes thatJobID and MatLotID are number fields.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

Maybe you are looking for

  • Runtime in JNLP

    When I run below code as standalone, the notepad is coming up successfully. but when i run through jnlp i could only see the frame with OK button. but the note pad is not popping up. I run this example in eclipse. Example.java import java.awt.*; impo

  • Upgrade from sp3 to sp4

    Dear all, Help me please with the following trouble i found during the subj. I had a directory with the BEA Platform installed. As a first step of the 'upgrade' procedure the platform has been uninstalled, then I killed all the directories left(where

  • Yahoo CardDAV an alternative to SLSs addressbook woes?

    Here I have one user on a brandnew mac mini SLS with 3000 Contacs in his Addressbook. As others complained all over these forums already in long threads, AB-Server is painfully slow with approx. more than 500 or even 1000 contacts in a users addressb

  • G4 Quicksilver and Tiger 10.4.6

    Hello-I am installing Tiger 10.4.6 from 10.2 This is a new unopened version of 10.4.6- Installed the driver and clicked restart as instructed and the G4 has been "thinking" for 30 minutes now. Is this a typical wait? Not sure if i should force quit a

  • Saving logos as jpg, eps, and png. What mode do I create each in? RGB or CMYK?

    Question... My client has asked for their logo as a JPG, EPS and PNG. They want a file ready to go, so they can fire off logos to whomever for whatever purpose. The Pantones are selected. My question, what mode do I create each format (jpg, eps, png)