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.
| Author |
Topic |
|
mrm23
Posting Yak Master
198 Posts |
Posted - 2008-11-13 : 05:07:45
|
| Hi,In the following trigger,i want to give the commented lines as condition. pls suggest me how to do tht**********************************************************************create trigger timesheet on [dbo].[project_log_time]after insert,updateas begin/* when there are no rows then*/update pt set act_date = case when cond 1 then task1 else when cond2 then task2 end /*when there are rows then*/update pt set act_date = case when cond 1 then task1 else when cond2 then task2 end end |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-11-13 : 05:14:23
|
| check the inserted pseudo table._______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.1 out! |
 |
|
|
mrm23
Posting Yak Master
198 Posts |
Posted - 2008-11-13 : 05:48:36
|
| then should i declare tht date as variable ? |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-11-13 : 05:51:25
|
| what do you mean by "when there are no rows"? when there are no rows where?_______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.1 out! |
 |
|
|
mrm23
Posting Yak Master
198 Posts |
Posted - 2008-11-13 : 06:10:16
|
| the trigger is written on project_log_time table. in this table entries a made against a task.the tasks are listed in project_task table.now,the condition is like:"when there are no rows for a particular task in the project_log_time table, then update...."the actual trigger is like this: ALTER TRIGGER [dbo].[Trg_timesheet]ON [dbo].[PROJECT_LOG_TIME] AFTER INSERT,UPDATEASBEGINDECLARE @plt_object INTSET @plt_object = SELECT plt_object FROM project_log_timedeclare @date datetimeset @date = select min(plt_date) from project_log_timeBEGINUPDATE ptSET pt.act_start_date = case when count(@plt_object) < 1 thenCASE WHEN pt.act_start_date IS NULL THEN i.plt_date ELSE CASE WHEN pt.act_start_date>i.plt_date THEN i.plt_date ELSE pt.act_start_date END ENDcase when count(@plt_object) > 1 then update ptset pt.act_start_date = case when pt.act_start_date is null then min(plt_date) else case when pt.act_start_date > i.plt_date then min(@date,pt.act_start_date) end endFROM dbo.project_task ptINNER JOIN inserted iON i.plt_object=pt.ptk_seq_noENDlet me know what is wrong with this |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-11-13 : 06:21:12
|
| are you sure you're supposed to be doing this in a trigger??? it makes no sense at all_______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.1 out! |
 |
|
|
|
|
|