vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| balajan (s_balaji@allsectech.com) writes: > But it is giving me an error. And the error is? Please include the full error message. > CREATE TRIGGER [InserCallTime] ON dbo.Agentcall > FOR INSERT > AS > Declare @mAgentCode integer > Select @mAgentCode = AgentCode from inserted CallDetails No, this you cannot do. A trigger fires once per statement, not once per row. Thus, if you insert more than one row, only one will be replicated to the other table. This is how the trigger should read (completely disregarding the problem with the linked server for the moment, since I don't know what your problem is there.) update [Y].misdb.dbo.Agent Set CallsForTheDay = 2 from [Y].misdb.dbo.Agent a join inserted i ON a.AgentCode = i.AgentCode If @@rowcount <> (SELECT count(*) FROM inserted) BEGIN INSERT [Y].misdb.dbo.Agent(AgentCode) SELECT AgentCode FROM inserted i WHERE NOT EXISTS (SELECT * FROM [Y].misdb.dbo.Agent a WHERE a.AgnentCode = i.AgentCode) End Not that this is likely to have shining performance. -- Erland Sommarskog, SQL Server MVP, sommar@algonet.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp |