Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trigger Troubleshooting

Author  Topic 

JohnnyLethal
Starting Member

7 Posts

Posted - 2012-05-08 : 14:27:00
Thanks in advance for the help. I'm new with triggers and struggling with this one. It should pick up punches from a timeclock and write them to another table. The trigger works great for the IN punches, but ignores the OUT punches and doesn't write them out.
Here's the trigger, when just the select statement is run, it returns both IN and OUT punches:

CREATE TRIGGER [dbo].[TMW_Punch_Timeclock] ON [dbo].[TIMESHEETITEM]
FOR INSERT
AS

INSERT INTO [dbo].[kronos_shiftschedules_log]
(ssl_id,
ssl_employeeid,
ssl_activitydate,
ssl_auditreason,
ssl_createdate,
ssl_createdby,
ssl_lastupdatedate,
ssl_lastupdateby,
ssl_puncheventid,
ssl_status)


SELECT
case when inserted.STARTPUNCHEVENTID = I.PUNCHEVENTID then inserted.STARTPUNCHEVENTID else inserted.ENDPUNCHEVENTID end
,P.PERSONNUM
,I.PUNCHDTM
,case when inserted.STARTPUNCHEVENTID = I.PUNCHEVENTID then 'LI' else 'LO' end
,I.PUNCHDTM
,SUBSTRING(C.CLNT,14,12)
,I.PUNCHDTM
,''
,case when inserted.STARTPUNCHEVENTID = I.PUNCHEVENTID then inserted.STARTPUNCHEVENTID else inserted.ENDPUNCHEVENTID end
,''
FROM inserted join person p on inserted.employeeid = p.PERSONID
join WTKEMPLOYEE E ON inserted.EMPLOYEEID = E.EMPLOYEEID
join VP_PUNCHITEM I ON (inserted.STARTPUNCHEVENTID = I.PUNCHEVENTID or inserted.ENDPUNCHEVENTID = I.PUNCHEVENTID)
join DATASOURCE D ON (I.PUNCHDATASOURCEID = D.DATASOURCEID)
join CLIENTCONTEXT C ON (D.CLIENTCONTEXTID = C.CLIENTCONTEXTID)
WHERE E.PAYRULEID = '3'
AND I.PUNCHOVERRIDE IS NULL

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-08 : 14:41:51
Please show us some sample data. It's really hard for us to help without it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

JohnnyLethal
Starting Member

7 Posts

Posted - 2012-05-08 : 14:45:55
Certianly, but can you help me decide what to post?
Would you like to see the data from main table the trigger sits on? or are you looking for a desc on the destination table?
Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-08 : 16:01:08
I'd like to see the data from the "inserted" trigger table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-08 : 16:10:16
I'd also like to see a few rows from the select statement.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

JohnnyLethal
Starting Member

7 Posts

Posted - 2012-05-08 : 17:10:42
Hi everyone, I went in another direction to solve my need. Thanks for all the help and I still hope to get better with triggers.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-08 : 17:21:21


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -