Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > sql server programming > june 2009 >

sql server programming : Trigger + Access + Sql -- different values?


Debbie Morrow
2/11/2004 10:20:19 AM
I've got an odd question ..

I have an application with an Access 2002 front end with
linked tables to a SQL 2000 backend. Users have always
been able to edit the SQL tables via access linked
tables/forms with no problem. I have now created an audit
table and using triggers to register each change. The
problem is, users want to be able to view the audit tables
through an access linked table .. and for some reason the
data in the audit table is not the same as the data on the
SQL server. However, if I import a copy of the audit table
the data is exactly the same. For example, if I make a
change to the column subtitle, the SQL table view will
show:

Subtitle ..... auditAction
Testing Snapshot A
Testing 1 SnapShot B

An imported copy of the table into Access will show:

Subtitle ..... auditAction
Testing Snapshot A
Testing 1 SnapShot B

While the linked Access table with show:

Subtitle .... auditAction
Testing Snapshot A
Testing Snapshot A

It doesn't make sense to me that the linked SQL table does
not show the same data as an imported table? Is there
caching going on somewhere?

The trigger is:

CREATE TRIGGER [TRIGGERPLAN2005] ON [dbo].[tblPlan2005]
FOR INSERT, UPDATE, DELETE
AS
IF (SELECT COUNT(*) FROM INSERTED) > 0 AND (SELECT COUNT
(*) FROM DELETED) > 0 BEGIN INSERT auditPlan2005
(auditUniqueID,auditQuarter,auditSubjectCourseAssign,auditL
Section,auditSubtitle, auditInstructorID,
auditInstructorPost, auditSupervise, auditEnrollLimit,
auditThirdWeekEnroll, auditNonUSNonEU, auditFilmCourse,
auditNotes,auditUser,auditDate, auditAction) SELECT
UniqueID, Quarter, SubjectCourseAssign, LSection,
Subtitle, InstructorID, InstructorPost, Supervise,
EnrollLimit, ThirdWeekEnroll, NonUSNonEU, FilmCourse,
Notes, User_Name(), GetDate(), 'SNAPSHOT A' From deleted
INSERT auditPlan2005
(auditUniqueID,auditQuarter,auditSubjectCourseAssign,auditL
Section,auditSubtitle, auditInstructorID,
auditInstructorPost, auditSupervise, auditEnrollLimit,
auditThirdWeekEnroll, auditNonUSNonEU, auditFilmCourse,
auditNotes,auditUser,auditDate,auditAction)
SELECT UniqueID, Quarter,SubjectCourseAssign,LSection,
Subtitle, InstructorID, InstructorPost, Supervise,
EnrollLimit, ThirdWeekEnroll, NonUSNonEU, FilmCourse,
Notes, User_Name(), GetDate(), 'SNAPSHOT B' From inserted
END ELSE IF (SELECT COUNT(*) FROM INSERTED) > 0 BEGIN
INSERT auditPlan2005
(auditUniqueID,auditQuarter,auditSubjectCourseAssign,auditL
Section,auditSubtitle,auditInstructorID,
auditInstructorPost, auditSupervise, auditEnrollLimit,
auditThirdWeekEnroll, auditNonUSNonEU, auditFilmCourse,
auditNotes,auditUser,auditDate, auditAction) SELECT
UniqueID, Quarter, SubjectCourseAssign, LSection,
Subtitle, InstructorID, InstructorPost, Supervise,
EnrollLimit, ThirdWeekEnroll, NonUSNonEU, FilmCourse,
Notes, User_Name(), GetDate(), 'ADDED' From inserted END
ELSE IF (SELECT COUNT(*) FROM DELETED) > 0 INSERT
auditPlan2005
(auditUniqueID,auditQuarter,auditSubjectCourseAssign,auditL
Section,auditSubtitle, auditInstructorID,
auditInstructorPost, auditSupervise, auditEnrollLimit,
auditThirdWeekEnroll, auditNonUSNonEU, auditFilmCourse,
auditNotes,auditUser,auditDate, auditAction) SELECT
UniqueID, Quarter, SubjectCourseAssign, LSection,
Subtitle, InstructorID, InstructorPost, Supervise,
EnrollLimit, ThirdWeekEnroll, NonUSNonEU, FilmCourse,
Notes, User_Name(), GetDate(), 'REMOVED' From deleted ENDIF
dmorrow NO[at]SPAM ucsd.edu
2/11/2004 12:51:28 PM
Answered my own question .. the audit tables needed an
Identity column in order to register the update, delete
and inserts corrected on the linked tables in Access.

-debbie
[quoted text, click to view]
sudhindra
6/29/2009 10:05:34 AM
can some one plz help me to convert the below code to sqlserver

CREATE OR REPLACE TRIGGER user_account_status_trg
AFTER INSERT OR UPDATE
OF STATUS
ON USER_ACCOUNT
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
c_job_id NUMERIC(16);
BEGIN
IF INSERTING THEN
INSERT INTO user_account_status_log (user_account_id, status, start_date_time, tenant_id) VALUES
(:NEW.user_account_id, :NEW.status, SYSDATE, :NEW.tenant_id);
ELSE
IF :NEW.status != :OLD.status THEN
INSERT INTO user_account_status_log (user_account_id, status, start_date_time, end_date_time, tenant_id) SELECT
:NEW.user_account_id, :OLD.status, :OLD.status_change_date, SYSDATE, :NEW.tenant_id FROM dual
WHERE NOT EXISTS (select 1 from user_account_status_log where user_account_id = :NEW.user_account_id and end_date_time is null);
UPDATE user_account_status_log set end_date_time = SYSDATE where user_account_id = :NEW.user_account_id and end_date_time is null;
INSERT INTO user_account_status_log (user_account_id, status, start_date_time, tenant_id) VALUES
(:NEW.user_account_id, :NEW.status, SYSDATE, :NEW.tenant_id);
END IF;
END IF;
END;
/

From http://www.google.co.in/search?hl=en&rlz=1G1GGLQ_ENIN330&q=example+IF+(SELECT+COUNT(*)+FROM+inserted)+>+0+AND+(SELECT+COUNT(*)+FROM+deleted)+=+0&meta=&aq=f&oq=

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button