MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 16th, 2004, 11:21 AM
prashantdalal prashantdalal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 prashantdalal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post MS Sql Trigger help needed

Hello,

I created following trigger in oracle and wnat to convert for
ms-sql database. Please help converting the following trigger to ms-sql



CREATE OR REPLACE TRIGGER negtwo_record AFTER UPDATE ON twdbs.transactions
REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW
declare
t_negtwo_date date;

begin
--as each update is applied, if the pmflag is set to -2, record a copy of that record out to the table_negtwo_tracking table.
select sysdate into t_negtwo_date from dual;
if :new.PMFLAG = '-2' then
begin
insert into table_negtwo_tracking (TRANS_ID, EMP_ID, TRANS_DATE, ACTIVITY_ID, RESOURCE_ID, TRANS_TYPE, PMFLAG, NEGTWO_DATE)
values :new.TRANS_ID, :new.EMP_ID, :new.TRANS_DATE, :new.ACTIVITY_ID, :new.RESOURCE_ID, :new.TRANS_TYPE, :new.PMFLAG, t_negtwo_date);
end;
else
null;
end if;
end;

Best Regards,
Prashant Dalal

Reply With Quote
  #2  
Old June 17th, 2004, 04:35 AM
pdo pdo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 3 pdo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This should do it:

Code:
CREATE TRIGGER negtwo_record ON twdbs.[Table Owner].transactions -- Actually you only need the name of the [Table Owner].[Table Name] unless the table is located in another database
AFTER UPDATE
AS
DECLARE  @t_negtwo_date datetime

SET  @t_negtwo_date = GETDATE()

INSERT INTO table_negtwo_tracking (TRANS_ID, EMP_ID, TRANS_DATE, ACTIVITY_ID, RESOURCE_ID, TRANS_TYPE, PMFLAG, NEGTWO_DATE)
SELECT	new.TRANS_ID, new.EMP_ID, new.TRANS_DATE, new.ACTIVITY_ID, new.RESOURCE_ID, new.TRANS_TYPE, new.PMFLAG, @t_negtwo_date
FROM	inserted as new
WHERE	new.PMFLAG = '-2'


-----------------------------
Pascal Dobrautz
http://www.sqlassi.net

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > MS Sql Trigger help needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT