SQLServer2008 标量函数
发布时间:2020-12-12 13:25:17 所属栏目:MsSql教程 来源:网络整理
导读:1)首先点击数据库-可编程行-标量函数,右键新建标量值函数 2)开始写函数 USE [lpp]GO/****** Object: UserDefinedFunction [dbo].[Rand2Valid] Script Date: 09/10/2016 09:19:34 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- ===============
1)首先点击数据库-可编程行-标量函数,右键新建标量值函数 2)开始写函数 USE [lpp] GO /****** Object: UserDefinedFunction [dbo].[Rand2Valid] Script Date: 09/10/2016 09:19:34 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,Name> -- Create date: <Create Date,> -- Description: <Description,> -- ============================================= ALTER FUNCTION [dbo].[Rand2Valid] ( -- Add the parameters for the function here @a int,@b int ) RETURNS decimal(10,1) AS BEGIN -- Declare the return variable here DECLARE @r decimal(10,1) -- Add the T-SQL statements to compute the return value here SELECT @r=cast(getRandData*(@b-@a)+@a as decimal(10,1)) from GetRandDataView -- Return the result of the function RETURN @r END3)全部选中这些函数,点击执行,然后才正式创建了,创建时把上面ALTER改为CREATE; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |