HOW TO CREATE A TRIGGER TO UPDATE A DATE FIELD WHEN RECORD IS MODIFIED

Hi,
I have a field (column)
SalesLeadLastModifiedDate
in the table
SalesPipeline
A record's field (SalesLEadLastModifiedDate) should be updated with current date and time every time any column in a record is modified. I'm new to SQL and can't figure out how to write this trigger. Could someone help me and also
refer literature that would give me independence? Online MSDN language without matching examples is not helping.
Tnx.,
IJ

Break it down into pieces.  Write a small script that updates some small (but more than 1) number of rows.  After updating the rows, write another update statement that will set your modified date column to the current date and time.  Once
you have that working, you can easily convert that into a trigger.  Pseudo-code would be:
begin tran;
select * from dbo.SalesPipeline where SalesPipelineID in (45, 76);
update dbo.SalesPipeline set <some column> = <something> where SalesPipelineID in (45, 76);
update dbo.SalesPipeline set <your date colum> = ?? where SalesPipelineID in (45, 76);
select * from dbo.SalesPipeline where SalesPipelineID in (45, 76);
rollback tran;
Notice the transaction control statements.  This will allow you to run the script, evaluate the result, and then revert all changes (leaving your database unchanged).  In turn, this will allow you to run the same script over and over and over again
and achieve (for the most part) the same results with each execution.  You can search the forums for examples of trigger code - just beware that many "solutions" are not necessarily well-written.

Similar Messages

  • How to create a RFC destination for extracting data to HANA

    Hello All,
    Could someone help me in providing a document or note on how to create a RFC destination for extracting data from SAP data source to HANA using SAP LT replication server ?
    I am able to create a data base connection while transforming data from non SAP data source,but wasnt able to transform data which is from SAP abap tables .

    Hi Venkatesh,
    In SM59 t.code we create RFC destinations.
    Go thru the video link for creating RFC destinations step by step
    How to setup a trusted RFC connection between SAP systems: a step-by-step guide - YouTube

  • How do I update a date field through CMP

    I wonder how to update a date field through CMP.
    For example, I can't update an employee table with following statement.
    employee.setHire_date('2002-03-20');
    Thanks,

    Thats correct......
    Try using the following code....
    String strDate ="2002-03-20";
    String date_fmt = "yyyy-MM-dd";
    java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(date_fmt);
    java.util.Date hireDate =null;
    hireDate =(Date) sdf.parse(strDate);
    employee.setHire_date(hireDate);
    Hope this helps
    Cheers
    --Venky                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to Create an Input Schedule Comparison with Data Using EVDRE

    Hello,
    I try implement the scenario described in "How to Create an Input Schedule Comparison with Data Using EVDRE".
    Once I am using the "Insert Function" from the panel and selecting the EVTIM function Excel crashes (see page 8 How to paper).
    Systems:
    BPC 7.0 NW SP02
    Office 2007
    BPCADminClient and BPCOfficeClient up to date
    Have anyone a solution?
    Thanks
    Oktay

    Hi Oktay -
    This function works in my BPC70NW SP02 system. Your issue might be that you are trying to access a TIME member that does not exist. Please make sure the offset value is a valid dimension member.
    I can confirm that EVTIM does allow the offset for base members (such as 2009.MAY) as well as parent nodes (such as 2009.Q1 or 2008.TOTAL)... BUT...the offset result of the EVTIM function needs to be a valid dimension member!
    Regards,
    Sheldon

  • How to create a new excel file using Excel Destination when Destination file not exists.

    how to create a new excel file using Excel Destination when Destination file not exists.

    Just need to set an expression for excel connectionstring and set delay validation to true and it will create it on the fly.
    The expression should return the full path with dynamic filename in each case.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to create a popup window that shows detail information when press submi

    hi,all
    how to create a popup window that shows detail information when press the submit button ?I mean,when I press the button "Sumit"there will appear a popup window that shows the detail information you typed before.it means are u sure to submit,it is like some confirmation window.
    how to do achieve this ?help plz .
    best regards
    hlee
    Edited by: hlee on 2011-4-15 上午1:26

    hey,vee
    thanks for your response,but i had already read this thread before i put up a new question.any way,thanks.
    best regards
    hlee

  • How do I change default settings in the author field when I edit or insert a comment in a PDF?

    How do I change default settings in the author field when I edit or insert a comment in a PDF?

    Generally it gets this info from the Identity in the preferences. Unfortunately, I know of no way to change the Login Name that shows up in the comments. I need to look at newer versions of Acrobat on other machines, this is AA8.

  • Update a date field using execute immediate statement..

    I need to update a date field dynamically .
    Below is the code I have written for the same..
    EXECUTE IMMEDIATE
    'UPDATE Temp_Emp ' ||
    ' SET ' || V_Fieldname || ' = ' || D_Value ||
    'WHERE Emp_Id = ' || 8447;
    I am getting the following error..
    ORA-00904: "AUG": invalid identifier
    Pls anyone have any ideas..
    Thanks,
    Xyz

    put D_Value in single quotes like this
    EXECUTE IMMEDIATE
    'UPDATE Temp_Emp ' ||
    ' SET ' || V_Fieldname || ' = ''' || D_Value ||''' WHERE Emp_Id = ' || 8447;

  • How do I tell Preview/Safari not to date-stamp when I print/save a webpage?

    How do I tell Preview/Safari not to date-stamp when I print/save a webpage as a PDF?
    There doesn't appear to be a Preference for this. Thanks.

    Oops, sorry, I was planning on selecting "helpful" and then "solved" for your reply, but the "solved" button has disappeared. Looks like I can only pick one.

  • Creating a trigger for update

    I have a table that consists of the following: product_id number, location number, qty number. product_id and location are primary keys.
    I want to create a trigger before an update and if the record doesn't exist that is trying to be updated, then I have to create the record.
    For example, if I want to do an update of the following:
    update inventory set qty = 80 where product_id=13 and location=45;
    Let's say that the record doesn't exist, how do I do this with a trigger.

    Hi,
    First of all i would like to clear one thing:
    IF you are trying to update any record and that record does not exist in table then trigger will not be called.
    "afiedt.buf" 10 lines, 236 characters
      1  CREATE OR REPLACE TRIGGER t_trig
      2  BEFORE UPDATE ON t
      3    FOR EACH ROW
      4    BEGIN
      5             DBMS_OUTPUT.PUT_LINE('Trigger has been  called!!!');
      6    EXCEPTION
      7       WHEN OTHERS THEN
      8               DBMS_OUTPUT.PUT_LINE('IN EXCEPTION:'||SQLERRM);
      9*  END;
    SQL>/
    Trigger created.
    SQL>DESC t;
    Name                                      Null?    Type
    NAME                                               VARCHAR2(20)
    SQL>SELECT * FROM t;
    NAME
    BBB
    1 row selected.
    SQL>SET SERVEROUTPUT ON
    SQL>
    SQL>UPDATE t SET NAME='XXX' WHERE name='AAA';
    0 rows updated.
    SQL>UPDATE t SET NAME='XXX' WHERE name='BBB';
    Trigger has been  called!!!  <-- Trigger called here
    1 row updated.So to achieve your result you have to do it outside the trigger.
    If you are updating trougha a procedure, after update statement you can use SQL%ROWCOUNT to get how many rows have been updated. If it zero you can insert the record.
    Regards

  • How dose AddPrinter.app trigger software update?

    Has any one figured out how AddPrinter triggers software udpate to download and install printer drivers? Because it would be really cool to be able to add printers from the command line and still be able to trigger software update to download the printer drivers.

    Thanks for the response, that is good to know!
    I agree that you shouldn't wipe out completely. In my case however, I use a database to track alot of changes in my app.
    By default, I create a copy of the source database, and the user's changes go to the copy. In my update, I released a new table in my database, but I'm guessing the user's database copy remained in their workspace. So essentially, any calls to the new table cause a system failure, or in my case a crash because the user's old version still referenced the old database.
    Any ideas on how to approach this kind of problem? Is there a way to query a database version? I am using a sqlite3 database. Perhaps my app can check the working version of the database? And overwrite if it sees an older version?
    Either that, or is there a way to modify the actual update/install process? So that my app will automatically clear a certain directory where my old database file is sitting?

  • How to create a trigger for particular value insertion?

    If I have a Table T, which has columns as A,B,C,D. I want to create a trigger to give an error message if someone inserts or updates T with values in A as '001' AND value in B as '99'
    Please reply soon....
    Thanks

    user8560155 wrote:
    I need a trigger only not a constraint...
    Why? Is there any valid reason for that?
    I tried the above trigger but it was not successful :(
    Can I use 'If statements' as well???The below will work..
    create table t
      a varchar2(10),
      b varchar2(10),
      c varchar2(10),
      d varchar2(10)
    create or replace trigger trig1
    after insert or update on t
    for each row
    --"trigger will be fired only when below condition is satisfied"
    when ( new.a = '001' or new.b = '99' )
    begin
    raise_application_error(-20000, 'Invalid value in A or B');
    end;
    insert into t(a) values('001');
    SQL Error: ORA-20000: Invalid value in A or B
    ORA-06512: at "SCOTT.TRIG1", line 2
    ORA-04088: error during execution of trigger 'SCOTT.TRIG1'
    insert into t(a) values('002');
    1 rows inserted.

  • How to know where all my Update of a field created records (Like when we have nested triggers)

    How do I know where all( in which tables) the new records are created when I've updated a field in a Table.
    I've updated a field it displayed. actually it updated only one row in my original table
    1 row effected.
    1 row effected
    1 row effected.
    1 row effected.
    four times.
    So I realized and seen the triggers defined for that table, then also I was able to find only one record inserted in a different table through record.
    How to know all the tables where all my update  ...cause to insert records.

    do you've a common field between tables or an audit column like datemodified?  If yes, you can use them to find out recently inserted records from the affected tables.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to create a trigger on a view

    Hello all,
    I am trying to create a trigger on a view that is used to update a few columns in the base table. Since I am new to trigger, an example will be appreciated.
    Thanks in advance.

    Are you sure that you need a trigger for this? Lots of folks that are new to triggers tend to overuse them before they understand the maintenance problems that having a bunch of triggers creates.
    That said, the Oracle documentation has an example of [creating an INSTEAD OF trigger on a view|http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_7004.htm#i2064426]
    Justin

  • How to create insert trigger to XI

    My scenario as follow:
    When the database is inserted, it trigger the proess in
    XI
    How can i solve the problem?
    Just use the JDBC Adapter? If so, how could i write the SQL?
    But i have seen the links about Document Formats for the Receiver JDBC Adapter,
    it seem like not having the action "trigger"
    Thank you for your reply

    Lawnrence,
    You need a SENDER JDBC Adapter and not a Receiver JDBC adapter for this purpose.
    When you are using your JDBC as a sender, then your JDBC will poll over your database and select the rows that satisfy your Select Query. Also, there is another field in your JDBC adapter that is very important and that is the Update satatement. Once your JDBC adapter executes your select query and selects rows from the database, you might not need those rows to be selected again. In this csse, you can use the Update statement to update the database.
    In the case of the receiver JDBC adapter, you can insert/ update/ delete data and execute stored prooedure into your databse.
    For more info, look at these links,
    http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/content.htm
    Regards,
    Bhavesh

Maybe you are looking for

  • I have an hp photosmart c7280 all-in-one series printer won't print. error message, system problem

    I have an HP Photosmart All-in-One C7280 series printer/fax/copier/scanner. I have been having issues with printing for the past few weeks. It is a wireless printer, with a jack into the wall (for fax) and it is plugged into a power source. I never u

  • How to add a signature at the end of each post

    How do you add a signature at the end of each post (if possible)? ^^right now, I just have to copy and paste that

  • Why do colours change in the printed document

    When I add a logo to my artwork in illustrator, import the illustrator file to a word template and print, it changes the printed colours dramatically..(black to blue, green to black and yellow to pink). Do I need to change a setting for that imported

  • My iphone is not getting started

    -iphone shows the image of a cable with an arrow with the symbol of itunes and  not getting started

  • Not running on AC

    Hey, new to Macs, IT for 5+ years, but i recently got my hands on a Macbook (white, 1.83 Core Duo, 2006) that wont charge or start on adapter only, the Magsafe stays green. It WILL start with a charged battery in though. I was wondering if anyone had