Sorry if this is confusing: I will try to be as specific as possible.
I am passing in @Detail- it can be blank, null, or have text
If @Detail is not null or blank, I need to check if AppraisalResponse.Detail is blank or null (- I think this is where I am running into so much trouble). If it is blank or null then I need to check if there is already a record in AppraisalHistory with this ID. If there is, I need to insert the blank record to history, otherwise not.
If @Detail is null. I need to check if there is already a record in Appraisal History with this ID. If there is, I need to insert the blank record to history, otherwise not.
IF @Detail is not null
AND (SELECT
COUNT(AppraisalResponseID)
FROM AppraisalResponseHistory
WHERE AppraisalResponseID = @AppraisalResponseID) >0
BEGIN
INSERT INTO AppraisalResponseHistory
( AppraisalResponseID,
PermissionID,
AppraisalTypeQuestionPromptID,
Detail,
ModifiedDate,
PersonID )
SELECT AppraisalResponse.ID,
AppraisalResponse.PermissionID,
AppraisalResponse.AppraisalTypeQuestionPromptID,
AppraisalResponse.Detail,
AppraisalResponse.ModifiedDate,
PersonID
FROM AppraisalResponse
WHERE AppraisalResponse.ID=@AppraisalResponseID AND AppraisalResponse.Detail<>@Detail
END
ELSE
IF COALESCE(@Detail, '') = ''
--if the reviewer is inserting a blank record after having filled in a response, insert into history
--if the blank record is the place holder, do not insert into history
AND (SELECT
COUNT(AppraisalResponseID)
FROM AppraisalResponseHistory
WHERE AppraisalResponseID = @AppraisalResponseID) >0
BEGIN
INSERT INTO AppraisalResponseHistory
( AppraisalResponseID,
PermissionID,
AppraisalTypeQuestionPromptID,
Detail,
ModifiedDate,
PersonID )
SELECT AppraisalResponse.ID,
AppraisalResponse.PermissionID,
AppraisalResponse.AppraisalTypeQuestionPromptID,
AppraisalResponse.Detail,
AppraisalResponse.ModifiedDate,
PersonID
FROM AppraisalResponse
WHERE AppraisalResponse.ID=@AppraisalResponseID AND AppraisalResponse.Detail<>@Detail
END
by: gjutrasPosted on 2007-08-09 at 11:02:48ID: 19664390
-- need empty history record if detail is null and it doesn't exist yet tID, D,null,nul l,'',GETDA TE(),null)
il) > 0)) > 0 tID, D,null,nul l,'',GETDA TE(),null)
IF @Detail is null OR LEN(@Detail) = 0
AND (SELECT
COUNT(AppraisalResponseID)
FROM AppraisalResponseHistory
WHERE AppraisalResponseID = @AppraisalResponseID) =0
BEGIN
INSERT INTO AppraisalResponseHistory
( AppraisalResponseID,
PermissionID,
AppraisalTypeQuestionPromp
Detail,
ModifiedDate,
PersonID )
values(@AppraisalResponseI
END
-- if detail isn't null or blank and Appraisal detail is null or blank and an id exists, insert blank record
IF @Detail is not null AND LEN(@Detail) > 0
AND (SELECT
COUNT(AppraisalResponseID)
FROM AppraisalResponseHistory
WHERE AppraisalResponseID = @AppraisalResponseID
and (AppraisalResponse.Detail is null OR LEN(AppraisalResponse.Deta
BEGIN
INSERT INTO AppraisalResponseHistory
( AppraisalResponseID,
PermissionID,
AppraisalTypeQuestionPromp
Detail,
ModifiedDate,
PersonID )
values(@AppraisalResponseI
END