| Author |
Topic |
|
stevo_3
Starting Member
20 Posts |
Posted - 2006-01-10 : 10:28:56
|
Hello,i got a trigger i get the folowwing error:Error 2739: The text, ntext, and image data types are invalid for local variablesBut the problem is these fields needs to be inserted absolutely in my database:Here is my trigger (very large one CREATE TRIGGER [portima1] ON dbo.workitem FOR INSERT, UPDATEASdeclare @id intdeclare @timestamp timestampdeclare @link_parent_number int declare @link_type_lookup_id intdeclare @number intdeclare @is_last nchardeclare @has_attachments nchardeclare @version intdeclare @source nvarchardeclare @external_reference nvarchardeclare @priority_lookup_id intdeclare @status_lookup_id intdeclare @category_lookup_id intdeclare @type_lookup_id intdeclare @category_tree_value nvarchardeclare @assigned_to_worker_id intdeclare @created_by_worker_id intdeclare @modified_by_worker_id intdeclare @created_by_worker_contact_id intdeclare @modified_by_worker_contact_id intdeclare @created_on datetimedeclare @start_on datetimedeclare @due_on datetimedeclare @modified_on datetimedeclare @minutes_spent intdeclare @action nvarchardeclare @title nvarchardeclare @managed_object_id intdeclare @contact_id intdeclare @tag_collection_id intdeclare @is_scheduled nchardeclare @bulletin_status nchardeclare @comment ntextdeclare @auxdata ntextdeclare @total_minutes_spent intdeclare @owned_by_worker_id intdeclare @_ResourceGuid uniqueidentifierdeclare @rating intdeclare @comment_visible_to_guest nchardeclare @rules_fired nvarchardeclare @updatelock nchardeclare @urgency_lookup_id intdeclare @impact_lookup_id intdeclare @close_code_lookup_id intdeclare @portimaid nvarchardeclare @officeid nvarchardeclare @ticketstatus nvarchardeclare @new_comment ntextIF EXISTS (SELECT * FROM workitem where portimaid=@portimaid)beginUPDATE workitemSET comment = comment + @new_commentend elseUPDATE workitemSET portimaid = SUBSTRING(title, 36, 6)UPDATE workitem SET officeid= SUBSTRING (title, 58, 5)UPDATE workitemSET workitem.contact_id= contact.id FROM workitem inner join contactON workitem.officeid=contact.title INSERT INTO workitem(id,link_parent_number,link_type_lookup_id,number,is_last,has_attachments,version,source,external_reference,priority_lookup_id,status_lookup_id,category_lookup_id,type_lookup_id,category_tree_value,assigned_to_worker_id,created_by_worker_id,modified_by_worker_id,created_by_worker_contact_id,modified_by_worker_contact_id,created_on,start_on,due_on,modified_on,minutes_spent,action,title,managed_object_id,contact_id,tag_collection_id,is_scheduled,bulletin_status,comment,auxdata,total_minutes_spent,owned_by_worker_id,_ResourceGuid,rating,comment_visible_to_guest,rules_fired,updatelock,urgency_lookup_id,impact_lookup_id,close_code_lookup_id)VALUES(@id,@link_parent_number,@link_type_lookup_id,@number,@is_last,@has_attachments,@version,@source,@external_reference,@priority_lookup_id,@status_lookup_id,@category_lookup_id,@type_lookup_id,@category_tree_value,@assigned_to_worker_id,@created_by_worker_id,@modified_by_worker_id,@created_by_worker_contact_id,@modified_by_worker_contact_id,@created_on,@start_on,@due_on,@modified_on,@minutes_spent,@action,@title,@managed_object_id,@contact_id,@tag_collection_id,@is_scheduled,@bulletin_status,@comment,@auxdata,@total_minutes_spent,@owned_by_worker_id,@_ResourceGuid,@rating,@comment_visible_to_guest,@rules_fired,@updatelock,@urgency_lookup_id,@impact_lookup_id,@close_code_lookup_id)sorry about the mess Anyone got an idea how i can solve this?Thx Steve |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-01-10 : 11:13:27
|
| You cannot declare a local variable of datatype text, ntext, and image.This trigger makes no sense, since you have no logic to populate any of the variables that you declared.What are you trying to accomplish?CODO ERGO SUM |
 |
|
|
stevo_3
Starting Member
20 Posts |
Posted - 2006-01-10 : 13:09:45
|
Hello,i'm going to explain what i want to achieve:i got a table workitem with folowwing fields:id(key),title, comment, ..., portimaid, officeid1 blabla, hello ,...., 559542 , 1234before inserting the record he needs to detect that he founds already the portimaid in the record list (unique field),so he needs to update the comment only of an existing record for example i want to add folowwing record:id(key),title ,comment , ..., portimaid, officeid55 , blabla2222, hello222 ,...., 559542 , 1234as you can see i just want that he adds to comment to this existing record sow i want to have this as result:1 blablablabla2222, hellohello222 ,...., 559542 , 1234-------------------------------------------------------------------if he doesn't detect the same portimaid do the folowwing:insert a whole new record: and these are all the fields that are coming from an application called altiris, but i don't know a command to add a whole record ThanksSteve |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
|
|
stevo_3
Starting Member
20 Posts |
Posted - 2006-01-10 : 14:27:09
|
Yes,maybe stored procedure but how i can add my record then,do i need to consult the "inserted" table ? Steve |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-10 : 14:40:36
|
| [code]if exists (select ... from workitem where ....)Begin Update workitem Set comment = comment + @new_comment, portimaid = SUBSTRING(title, 36, 6) officeid= SUBSTRING (title, 58, 5) FROM workitem inner join contact ON workitem.officeid=contact.title EndElseBegin INSERT INTO workitem (....) values (....)End[/code] |
 |
|
|
stevo_3
Starting Member
20 Posts |
Posted - 2006-01-10 : 15:07:19
|
Sorry to bother you but i still don't have the clue:in the trigger:CREATE TRIGGER dbo.portima1FOR INSERT, DELETEASUSE workitemEXEC sp_portima1(?)GOin the procedure:CREATE PROCEDURE portima1 declare @portimaid nvarcharbeginif exists (select portimaid from workitem where SUBSTRING(title, 36, 6)=portimaid)Begin Update workitem Set comment = comment + @new_comment, portimaid = SUBSTRING(title, 36, 6) officeid= SUBSTRING (title, 58, 5) FROM workitem inner join contact ON workitem.officeid=contact.title EndElseBegin INSERT INTO workitem (id,link_parent_number,link_type_lookup_id,number,is_last,has_attachments,version,source,external_reference,priority_lookup_id,status_lookup_id,category_lookup_id,type_lookup_id,category_tree_value,assigned_to_worker_id,created_by_worker_id,modified_by_worker_id,created_by_worker_contact_id,modified_by_worker_contact_id,created_on,start_on,due_on,modified_on,minutes_spent,action,title,managed_object_id,contact_id,tag_collection_id,is_scheduled,bulletin_status,comment,auxdata,total_minutes_spent,owned_by_worker_id,_ResourceGuid,rating,comment_visible_to_guest,rules_fired,updatelock,urgency_lookup_id,impact_lookup_id,close_code_lookup_id) values (....) **** This is just my problem: i don't have values for this, they are automaticly updated by an application (altiris helpdesk solution) designed in ASP (.NET) there is just a command who just sais add record and i need to analyze the records before i may add them EndendThis is going to deep for me Steve |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-10 : 15:23:53
|
| -- Nothing to do with triggers --Write a stored procedure, which takes the data u supplied as input parametersIn the procedure do the coding as I have given[I gave the logic only u do the filling of the remaining]The code is checking whether a particular record exists, and if so update it (what needs to be updated will be determined by u)if no record, insert the dataInvoke ur stored procedure with appropriate parameters from ur client application. |
 |
|
|
|
|
|