DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Trigger updating a collumn

  1. #1
    Ed Kummel Guest

    Trigger updating a collumn


    I have the following trigger:
    CREATE TRIGGER [TTEST] ON [newt_pkg]
    FOR insert, update
    AS

    IF (select readme_file from newt_pkg) IS NULL
    UPDATE newt_pkg
    set readme_exist = "No"
    from newt_pkg
    else
    UPDATE newt_pkg
    set readme_exist = "Yes"
    from newt_pkg


    Essentially, what I'm trying to do is update one column based on the contents
    of another column.
    I want to test the field "readme_file" and if it is empty (NULL) set the
    field readme_exit to have the value "No", otherwise make the field value
    "Yes"

    I've placed this in my database and the field "readme_exist" isn't updating.
    I've never done this before, so if anyone sees something I've done wrong
    here, can you point it out for me?
    Ed
    web/gadget guru

  2. #2
    Join Date
    Dec 2003
    Posts
    8
    The following "real time" sample may give you some ideas:
    Code:
    CREATE trigger SATGITMI on dbo.ITEM for INSERT as
    /*-----------  if not jewlery exit ---------*/
    declare @wItemTypeCode       varchar (2)
    declare @wItemStatus       varchar (10)  
     
    select @wItemTypeCode = inserted.ItemTypeCode from inserted 
    select @wItemStatus = inserted.ItemStatus from inserted 
    if @wItemStatus = 'In Setup' goto ExitTrigger
    if @wItemStatus = 'On Hold' goto ExitTrigger
    if @wItemTypeCode <> 'J' goto ExitTrigger
    /*---------- DECLARATIONS ----------*/
    	declare @wLegacyIdNum       varchar (22)  
    	declare @wAlternateIdNum    varchar (15)  
    	declare @wChangeType        varchar (1)   
    	declare @wChangeDate        DateTime  
    	declare @wChangedEntity     varchar (30)  
    	declare @wItemId            int 
    
    
    /*---------- read into variables  ----------*/
    	select
    		  @wLegacyIdNum       = LegacyIdNum
    		 ,@wAlternateIdNum    = AlternateIdNum
    		 ,@wItemId            = ItemId 
    	    from inserted
    	select 	@wChangeType    = 'I'     
    	select 	@wChangeDate    = GetDate()      
    	select 	@wChangedEntity = 'ITEM'    
    
    /*-- Added 04/22/99 --- Delete existing rows for this item ---*/
    	Delete from MODIFIED_ITEMS 
                   where ItemId = @wItemId
    
    
    /*---------- insert  ----------*/
    	    insert into MODIFIED_ITEMS (
    		 LegacyIdNum
    		,AlternateIdNum
    		,ChangeType
    		,ChangeDate
    		,ChangedEntity
    		,ItemId  
     		) values (
    		 @wLegacyIdNum
    		,@wAlternateIdNum
    		,@wChangeType
    		,@wChangeDate
    		,@wChangedEntity
    		,@wItemId  
    		)
    ExitTrigger:
    RETURN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center