Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Different trigger problem

Author  Topic 

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2010-08-04 : 17:42:27
Hi I'm trying to crteate new trigger.
Don't tell me off for not using Raiserror - (i'm looking in ti that and trying to learn about it)

My more pressing problem here is I ge a message saying

Msg 4104, Level 16, State 1, Procedure SUMMARY_UPDATE, Line 15
The multi-part identifier "calllog.repyear" could not be bound.
Msg 4104, Level 16, State 1, Procedure SUMMARY_UPDATE, Line 15
The multi-part identifier "calllog.repmonth" could not be bound.


Here is the trigger

===================

USE [DB1]
GO
/****** Object: Trigger [dbo].[DURATION_UPDATE] Script Date: 08/04/2010 18:46:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <ICW>
-- Create date: <04/08/10>
-- Description: <Trigger to update the summary fields in calllog>
-- =============================================
create TRIGGER [dbo].[SUMMARY_UPDATE] ON [dbo].[Calllog]
FOR INSERT, UPDATE

AS

Declare @CalliD Varchar(8)
Declare @Year varchar(4)
Declare @Month varchar(9)

Select @callid=Callid FROM inserted WHERE
isnull(calllog.repyear,'') > ''
AND
isnull(calllog.repmonth,'') > ''

IF @Callid IS NOT NULL
Begin

Select @Year = calllog.repyear
from calllog
where callid = @callid

Select @Month = calllog.repMonth
from calllog
where callid = @callid


UPDATE CallLog
set calllog.repnumreps = t1.repsnum
from calllog,
(
select count(callid) as "repsnum" from calllog
where calllog.swerncode in (select swerncode from calllog where callid = @callid) and
Month (cast(faultstart as datetime)) = Datepart(Month,(@Month))
AND
Year(cast(faultstart as datetime)) = Datepart(Year,(@year)))
as "t1"
Where calllog.CallID = @CallID



END

Sachin.Nand

2937 Posts

Posted - 2010-08-05 : 02:40:19
quote:
Originally posted by icw

Hi I'm trying to crteate new trigger.
Don't tell me off for not using Raiserror - (i'm looking in ti that and trying to learn about it)

My more pressing problem here is I ge a message saying

Msg 4104, Level 16, State 1, Procedure SUMMARY_UPDATE, Line 15
The multi-part identifier "calllog.repyear" could not be bound.
Msg 4104, Level 16, State 1, Procedure SUMMARY_UPDATE, Line 15
The multi-part identifier "calllog.repmonth" could not be bound.


Here is the trigger

===================

USE [DB1]
GO
/****** Object: Trigger [dbo].[DURATION_UPDATE] Script Date: 08/04/2010 18:46:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <ICW>
-- Create date: <04/08/10>
-- Description: <Trigger to update the summary fields in calllog>
-- =============================================
create TRIGGER [dbo].[SUMMARY_UPDATE] ON [dbo].[Calllog]
FOR INSERT, UPDATE

AS

Declare @CalliD Varchar(8)
Declare @Year varchar(4)
Declare @Month varchar(9)

Select @callid=Callid FROM inserted WHERE
isnull((select top 1 calllog.repyear from calllog),'') > ''
AND
isnull((select top 1 calllog.repmonth from calllog),'') > ''

IF @Callid IS NOT NULL
Begin

Select @Year = calllog.repyear
from calllog
where callid = @callid

Select @Month = calllog.repMonth
from calllog
where callid = @callid


UPDATE CallLog
set calllog.repnumreps = t1.repsnum
from calllog,
(
select count(callid) as "repsnum" from calllog
where calllog.swerncode in (select swerncode from calllog where callid = @callid) and
Month (cast(faultstart as datetime)) = Datepart(Month,(@Month))
AND
Year(cast(faultstart as datetime)) = Datepart(Year,(@year)))
as "t1"
Where calllog.CallID = @CallID



END



Check the above part of the query marked in red


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-05 : 03:23:30
"
"Select @callid=Callid FROM inserted WHERE
isnull(calllog.repyear,'') > ''
AND
isnull(calllog.repmonth,'') > ''


You are referring to calllog but there is no table with that name in that statement. The actual table is inserted (yes, inserted is actually a version of calllog, but as fas as SQL is concerned at this point all it has is a table called inserted).

Don;t forget to use RAISERROR
Go to Top of Page
   

- Advertisement -