I have a table in SQL Server. That contains 2 fields the Diagnosis code and the HCC Code. The HCC Code is based on the Diagnosis Code and I have another database on the same server that has a lookup table for every Diagnosis code and the HCC Code. I'm trying to set up an insert trigger that will update the HCC Field depending on what is entered in the Diagnosis but my Syntax isn't working
CREATE TRIGGER hvvmgrpt.dbo.T_hcc ON hosp_hcc AFTER INSERT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; update set HCC = get_HCC(Select I.diag from inserted I) -- Insert statements for trigger here END GO
CREATE FUNCTION [dbo].[GET_HCC] ( -- Add the parameters for the function here @ICD as varchar(20) ) RETURNS Varchar(10) AS BEGIN -- Declare the return variable here DECLARE @result varchar(10) -- Add the T-SQL statements to compute the return value here Set @result = (SELECT a.hcc from hccsql.dbo.hcc a where left(a.icd9,3) = left(@icd,3)) -- Return the result of the function RETURN @result END