Hey guys,I now have a trigger which is working afetr some help from this forum. The trigger is shown below:UPDATE ctSET [text] = CASE WHEN ct.longflag = 1 THEN CAST(ct.[text] AS VARCHAR(MAX)) ELSE ct.shorttext END + '; ' + REPLACE(i.shortnarrative, '*Fixed fee for ', '') + '; 'FROM casetext ctINNER JOIN inserted i ON ct.caseid = i.caseidWHERE ct.texttype = '_B'AND ct.longflag = 1AND SUBSTRING(i.shortnarrative, 1, 1) = '*'UPDATE ctSET ct.shorttext = CASE WHEN LEN(ct.shorttext) + LEN(i.shortnarrative) < 252 THEN ct.shorttext + ' ' + + REPLACE(i.shortnarrative, '*Fixed fee for ', '') + '; ' ELSE NULL END, ct.longflag = CASE WHEN LEN(ct.shorttext) + LEN(i.shortnarrative) < 252 THEN ct.longflag ELSE 1 END, ct.[text] = CASE WHEN LEN(ct.shorttext) + LEN(i.shortnarrative) < 252 THEN ct.[text] ELSE ct.shorttext + '; ' + REPLACE(i.shortnarrative, '*Fixed fee for ', '') + '; ' ENDFROM casetext ctINNER JOIN inserted i ON ct.caseid = i.caseidWHERE ct.texttype = '_B'AND ct.longflag <> 1AND SUBSTRING(i.shortnarrative, 1, 1) = '*'INSERT INTO casetext(caseid, texttype, textno, class, [language], modifieddate, longflag, shorttext, [text])SELECT i.caseid, '_B', 0, NULL, NULL, NULL, 0, REPLACE(i.shortnarrative, '*Fixed fee for ', '') + '; ', NULLFROM inserted iWHERE NOT EXISTS( SELECT * FROM casetext ct WHERE ct.caseid = i.caseid AND ct.texttype = '_B')AND SUBSTRING(i.shortnarrative, 1, 1) = '*'
Now I seem to have this working I need to make some further changes to meet a business requirement. I need to prevent certain rows being acted upon if a specific row was entered at the same time (1 or more rows can be entered into the parent table at any one time). One of the columns in the parent table is WIPCODE, so imagine the following was entered:WIPCODEP001P002P009P055What I need to do is ignore the rows which have a WIPCODE of P001 and P002 if a row with a WIPCODE of P009 is inserted by the user at the same time. I've tried using something like the following but it doesn't seem to do what I want.if (select count(*) from inserted where wipcode = 'P001') = 1 begin delete from inserted where wipcode in ('P009SC', 'P092SC', 'P9A1SC', 'P9A2SC', 'P9P9SC') endDo you have any ideas as to how I could achieve this? I hope this all makes sense and any help would be much appreciated.Chris