Hi,
You are Compaing NULL in wrong way. Use "IS NULL" for NULL Comparision not "=".
Check the links...
Comparison Operators (Transact-SQL)[
^]
SQL Operators[
^]
-- I changed your Trigger Code. Check the following Script....
USE [PRSAppTest_TST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trg_URPatients]
ON [dbo].[Patients]
FOR INSERT
AS
BEGIN
DECLARE @PCPID varchar(50)
DECLARE @Cnt int
DECLARE @PatientID varchar(50)
SET @PatientID = (SELECT top(1) PatientID from INSERTED)
SET @PCPID = (select top(1) UserId from users where PCPGroupID=(SELECT top(1) PCPID from INSERTED))
if @PatientID IS NULL
begin
return
end
else
begin
insert into UserRef(PatientID,AssignedBy,AssignedTo,ReasonOfAccs,EndDate)
values(@PatientID,@PCPID,@PCPID,'PCP',Dateadd(d,60,GETDATE()))
end
END
GVPrabu