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;