"Elvin" <Elvin@discussions.microsoft.com> wrote in message
news:5FB45615-8FF6-4125-BA4E-613CC79FEC2A@microsoft.com...
> The problem is not able to insert record into another database
> ([Server1].[DB1].[dbo].[Table2]) when there is a inserted event in the
> trigger, i have try create a same table into a same database then it work
> ([dbo].[Table2]) , so the question is how to allow the trigger insert a
> record into another database table when there is a inserted event?
>
> "Uri Dimant" wrote:
>
>> Elvin
>> What is the error?
>>
>>
>>
>>
>> "Elvin" <Elvin@discussions.microsoft.com> wrote in message
>> news:E656C278-CA8F-49CE-A725-2479657E92CA@microsoft.com...
>> > Hi,
>> > I have take out the [Server1] but still no luck, when there is a
>> > inserted
>> > record in table1, it still cannot insert into table2 and this cause no
>> > record
>> > have insert into table1 also. If i change to same database table then
>> > it
>> > work...any clue...
>> >
>> >
>> > ALTER TRIGGER [Trigger1]
>> > ON [dbo].[tblTable1]
>> > AFTER INSERT
>> > AS
>> > BEGIN
>> > -- SET NOCOUNT ON added to prevent extra result sets from
>> > -- interfering with SELECT statements.
>> > SET NOCOUNT ON;
>> > DECLARE @ResourceID int
>> > DECLARE @Call_Type varchar(8)
>> > DECLARE @Destination_Type varchar(20)
>> >
>> > SELECT
>> > @ResourceID=ResourceID,@Call_Type=Call_Type,@Destination_Type=Destination_
>> > Type FROM inserted
>> >
>> > IF @Call_Type='Outgoing'
>> > BEGIN TRY
>> > INSERT INTO [Server1].[DB1].[dbo].[Table2]
>> > ([ResourceID]
>> > ,[Call_Type]
>> > ,[Destination_Type])
>> > VALUES
>> > (@ResourceID,
>> > @Call_Type ,
>> > @Destination_Type)
>> > END TRY
>> > BEGIN CATCH
>> > INSERT INTO ErrorMsg VALUES (
>> > ltrim(str(error_number())),error_message())
>> > END CATCH
>> > END
>> >
>> > "Tony Rogerson" wrote:
>> >
>> >> Change
>> >> INSERT INTO [Server1].[DB1].[dbo].[Table2]
>> >>
>> >> To
>> >> INSERT INTO [DB1].[dbo].[Table2]
>> >>
>> >> Please post the error you are getting.
>> >>
>> >> Note, no error will be inserted into ErrorMsg because the whole
>> >> trigger
>> >> is
>> >> inside a transaction and your failure will cause it to roll back.
>> >>
>> >> --
>> >> Tony Rogerson
>> >> SQL Server MVP
>> >>
http://sqlserverfaq.com - free video tutorials
>> >>
>> >>
>> >> "Elvin" <Elvin@discussions.microsoft.com> wrote in message
>> >> news:927B5FE9-2A73-4046-BDD8-F3F7A970AD24@microsoft.com...
>> >> > Hi! When I try to insert a record to another database from a INSERT
>> >> > trigger,
>> >> > it failed to insert any record. It also did not raise any error
>> >> > message.
>> >> > It
>> >> > only success when i use the same database. Please advice! Thanks!
>> >> >
>> >> > note:Both database are stored in same server.
>> >> >
>> >> > Below is the trigger :-
>> >> >
>> >> > set ANSI_NULLS ON
>> >> > set QUOTED_IDENTIFIER ON
>> >> > go
>> >> >
>> >> >
>> >> > ALTER TRIGGER [Trigger1]
>> >> > ON [dbo].[tblTable1]
>> >> > AFTER INSERT
>> >> > AS
>> >> > BEGIN
>> >> > -- SET NOCOUNT ON added to prevent extra result sets from
>> >> > -- interfering with SELECT statements.
>> >> > SET NOCOUNT ON;
>> >> > DECLARE @ResourceID int
>> >> > SELECT @ResourceID=CAST(inserted.Calling_Number AS INT)
>> >> > IF inserted.Call_Type='Outgoing'
>> >> > BEGIN TRY
>> >> > INSERT INTO [Server1].[DB1].[dbo].[Table2]
>> >> > ([ResourceID]
>> >> > ,[Call_Type]
>> >> > ,[Destination_Type])
>> >> > VALUES
>> >> > (@ResourceID,
>> >> > @Call_Type ,
>> >> > @Destination_Type)
>> >> > END TRY
>> >> > BEGIN CATCH
>> >> > INSERT INTO ErrorMsg VALUES (
>> >> > ltrim(str(error_number())),error_message())
>> >> > END CATCH
>> >> > END
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>