alter Trigger UT_Project_tasks_Update on Project_tasks
for Update
AS
declare @pj_code varchar(20)
declare @pj_duration INT
declare @pj_id INT
declare @pj_start numeric
declare @pj_end numeric
declare @a datetime
declare @b datetime
if (update(pj_start) or update(pj_end))
begin
select @pj_start = pj_start, @pj_end = pj_end, @pj_id = pj_id, @pj_code = pj_code from inserted
select @a = DATEADD(SECOND, @pj_start/1000, '1970-01-01 09:00:00')
select @b = DATEADD(SECOND, @pj_end/1000, '1970-01-01 09:00:00')
select @pj_duration = datediff(day, @a, @b)
update Project_tasks set pj_duration = @pj_duration
where pj_id = @pj_id and pj_code = @pj_code
end
---------
위의 쿼리의 pj_start = 1361977200000 , pj_end = 1368025199999
로 DB에 값이 저장되어 있습니다.
업데이트시에 timestamp 값으로 날짜를 뽑아와서.. pj_duration에 날짜 차이값을 저장해 주는 건데..
pj_duration 자꾸 null 로 들어가네요..
강제로 @pj_start, @pj_end 에 값을 넣고 하나씩 검증해보면.. 개별 @값은 잘 나오는데요..
@pj_duration 에 실제 update될때 null로 들어가 버리네요..
트리거를 검증 해 볼 수 있는 방법은 혹시 없나요?
Comment 1
-
건우아빠
2013.06.20 14:30
내용상으로는 잘못된게 없는데 혹시 업데이트시 한row씩만 업데이트 되는지 여러row가 한꺼번에 업데이트가 되는지요 ?
여러row가 한꺼번에 업데이트가 될시에는 한로우만 처리되고 나머지는 처리가 안되어 있을듯 합니다.
update a
set a.pj_duration = datediff(day, DATEADD(SECOND, a.pj_start / 1000, '1970-01-01 09:00:00')
, DATEADD(SECOND, a.pj_end / 1000, '1970-01-01 09:00:00') )
from inserted a join Project_tasks b on a.pj_id = b.pj_id
and a.pj_code = b.pj_code