sql server 中标量值函数根据id返回结果
USE [OA_WEB_DB] GO /****** Object: UserDefinedFunction [dbo].[CountResult] Script Date: 05/20/2013 16:05:04 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER function [dbo].[CountResult](@scode varchar(10)) Returns real As Begin Declare @avg real Declare @code varchar(11) Set @code=@scode Select @avg=COUNT(*) from OA_DT_Attach where file_id=@code and deleted=0 Return @avg End