Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to save different values into a new table from a trigger?

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
I am a novice for sql server 2000. Right now I have a problem need to be solved. I wrote a trigger to copy the inserted records into a new table. But there is a field need to save as a different value into the new table. In this case, I want to save the M and F as sex value instead of Male and Female. How can this be done in sql server 2000?

My trigger is like this.
CREATE TRIGGER [CopyPalmProcedure] ON dbo.Procedure_palm
FOR INSERT
AS

Declare @insertedCount Int
set @insertedCount = (select Count(*) From Inserted )

if (@insertedCount > 0 ) Begin

INSERT INTO [ProcedureData]
( DateOfProc,
ResidentName,
Rotation,
PtFirstName,
PtLastName,
DOB,
Sex,
Location,
MedRedNo)
SELECT DateOfProc,
ResidentName,
Rotation,
PtFirstName,
PtLastName,
DOB,
Sex,
Location,
MedRedNo
FROM INSERTED
End


thanks

longmatch
 
Does this do the trick?

CREATE TRIGGER [CopyPalmProcedure] ON dbo.Procedure_palm
FOR INSERT
AS

Declare @insertedCount Int
set @insertedCount = (select Count(*) From Inserted )

if (@insertedCount > 0 ) Begin

INSERT INTO [ProcedureData]
( DateOfProc,
ResidentName,
Rotation,
PtFirstName,
PtLastName,
DOB,
Sex,
Location,
MedRedNo)
SELECT DateOfProc,
ResidentName,
Rotation,
PtFirstName,
PtLastName,
DOB,
Left(Sex,1),
Location,
MedRedNo
FROM INSERTED
End

--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top