| Author |
Topic |
|
steamngn
Constraint Violating Yak Guru
306 Posts |
Posted - 2006-02-06 : 17:02:36
|
Hi All,I can't seem to figure out the problem here. I have this trigger that I wrote to prevent a user from cancelling a ticket(PS_TKT_HDR) that is on the schedule(TimeTable). This works ok if I change @a to a ticket number like '12345' and run it in QA, but if I put it on PS_TKT_HDR as a trigger I get 'dataset not in edit mode' when I try to open a ticket in our app. There are other triggers on this table; could that be the problem? I've looked and looked, but I just can't get it...Help!begindeclare@DAT varchar(12),@MSG varchar(60),@1 T_DOC_NO,@2 T_DOC_NO,@3 T_DOC_NO,@4 T_DOC_NO,@5 T_DOC_NO,@6 T_DOC_NO,@7 T_DOC_NO,@8 T_DOC_NO,@9 T_DOC_NO,@10 T_DOC_NO,@11 T_DOC_NO,@12 T_DOC_NO,@13 T_DOC_NO,@14 T_DOC_NO,@15 T_DOC_NO,@16 T_DOC_NO,@17 T_DOC_NO,@a T_DOC_NOset @a=(select i.tkt_no from inserted iinner join ps_tkt_hdr hon h.tkt_no=i.tkt_noand h.str_id=i.str_idand h.sta_id=i.sta_idwhere i.doc_stat='C'and i.DOC_TYP='O')if @a is not nullbeginDECLARE chk_Cursor CURSOR FORSELECT svc_dat,time01,time02,time04,time05,time07,time08,time10,time11,time13,time14,time16,time17FROM timetablewhere svc_dat>getdate()OPEN chk_CursorFETCH NEXT FROM chk_Cursorinto @DAT,@1,@2,@4,@5,@7,@8,@10,@11,@13,@14,@16,@17WHILE @@FETCH_STATUS = 0BEGINif @a in(@1,@2,@4,@5,@7,@8,@10,@11,@13,@14,@16,@17)beginset @MSG='**Cannot Cancel: Ticket is scheduled for '+ @DATraiserror(@MSG,18,1)endFETCH NEXT FROM chk_Cursorinto @DAT,@1,@2,@4,@5,@7,@8,@10,@11,@13,@14,@16,@17ENDendCLOSE chk_CursorDEALLOCATE chk_Cursorend There's never enough time to type code right, but always enough time for a hotfix... |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-02-06 : 17:29:02
|
| Haven't looked at it but try adding a set nocount on.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
steamngn
Constraint Violating Yak Guru
306 Posts |
Posted - 2006-02-06 : 20:44:31
|
| Hey nr,No go, I tried that. With my limited knowledge, that was the only thing I could think of. I read something in one of my textbooks (finally going to school) about triggers not working well together if they are poorly written, but I couldn't quite figure it out. If you can tell me what to look for, I would like to try and figure it out on my own (HAHAHAHAHA!) first. No better way to learn how to solve a problem than to jump right into the fire...AndyThere's never enough time to type code right, but always enough time for a hotfix... |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-02-06 : 21:08:21
|
| I take it the trigger is on ps_tkt_hdr and you are only catering for single row updares?if soif exists (select * from inserted where i.doc_stat='C' and i.DOC_TYP='O')beginselect top 1 @msg = '**Cannot Cancel: Ticket is scheduled for ' + convert(varchar(12),svc_dat)from timetable tjoin insertd ion i.tkt_no in (time01,time02,time04,time05,time07,time08,time10,time11,time13,time14,time16,time17)where t.svc_dat > getdate()and i.doc_stat='C' -- not neededand i.DOC_TYP='O' -- not neededif @MSG is not nullbeginraiserror(@MSG,18,1)rollback trn -- not needed if error is handled in appendend==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
steamngn
Constraint Violating Yak Guru
306 Posts |
Posted - 2006-02-08 : 12:31:26
|
| Hey nr,That did it, and I learned a better way to write the trigger without all those local variables...THANKS!AndyThere's never enough time to type code right, but always enough time for a hotfix... |
 |
|
|
|
|
|