I have a table with 4 different status fields. I have a stored procedure that would work for updating each one, the only difference would be the name of the field that was to be updated. Being new at this, I tried:
CREATE PROCEDURE [dbo].[pPermit_UpdateForms]
@Field varchar(20),
@PermitId int,
@Status int
AS
UPDATE tEnvironmentalHealth
SET @Field = @Status
WHERE PermitId = @PermitId
GO
Someone explained this would not work, and suggested using the EXEC command. Something like this:
CREATE PROCEDURE [dbo].[pPermit_UpdateForms]
@Field varchar(20),
@PermitId int,
@Status int
AS
Exec
("UPDATE tEnvironmentalHealth
SET" + @Field + "= @Status WHERE
PermitId = @PermitId"
GO
But that didn't work either. Can someone point me in the right direction? I've never used EXEC before. Any help would be appreciated...Thanks!
CREATE PROCEDURE [dbo].[pPermit_UpdateForms]
@Field varchar(20),
@PermitId int,
@Status int
AS
UPDATE tEnvironmentalHealth
SET @Field = @Status
WHERE PermitId = @PermitId
GO
Someone explained this would not work, and suggested using the EXEC command. Something like this:
CREATE PROCEDURE [dbo].[pPermit_UpdateForms]
@Field varchar(20),
@PermitId int,
@Status int
AS
Exec
("UPDATE tEnvironmentalHealth
SET" + @Field + "= @Status WHERE
PermitId = @PermitId"
GO
But that didn't work either. Can someone point me in the right direction? I've never used EXEC before. Any help would be appreciated...Thanks!