> >FUNCTION ResolveToMaster (@cUnknown varchar(10)) >RETURNS varchar(10) >AS >begin > > >declare @MasterRef varchar(10) > >select @MasterRef = null > > >select @MasterRef = (Select Distinct MasterRef from Claim where MasterRef = @cUnknown) > >if @MasterRef is null >begin > select @MasterRef = (Select Distinct MasterRef from Claim where CustomerRef = @cUnknown) > >end > >if @MasterRef is null > begin > select @MasterRef = (Select Distinct MasterRef from Claim where ClaimRef = @cUnknown) > > end > > >Return @MasterRef >end > >>
SqlConnection sConn = new SqlConnection ("Data Source=server;integrated Security=sspi;initial catalog=myDatabase;"); SqlCommand cmd = new SqlCommand("select dbo.ResolvetoMaster(@cUnknown)", sConn); SqlParameter iv = cmd.Parameters.Add("@cUnknown", SqlDbType.VarChar, 10); sConn.Open(); iv.Value = "ValToCheck"; string retVal = (string)cmd.ExecuteScalar(); sConn.Close();There are other ways too.