sql 标量值函数的创建于使用

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION DicName 
(
	@TypeId nvarchar(32),
	@Code nvarchar(32)
)
RETURNS nvarchar(64)
AS
BEGIN
	DECLARE @Name nvarchar(64)

	SELECT @Name = isnull(max(TNAME), @Code) from Name
	where TYPEID = @TypeId and CODE = @Code

	RETURN @Name

END
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO



select *
,(select isnull(sum(typeid),0) from userType as B
where B.usersid=A.id) as TotalDetain
from users as A

 

posted on 2012-12-07 10:43  zmmlczy  阅读(270)  评论(0编辑  收藏  举报

导航