之所以说是和isnull类似的SQL函数,是因为isnull(@canshu,0)当传入的参数是null值时,就返回0.
而我想写的函数是这样的
当传入一个参数(decmail类型)时,如果大于100,则返回100
------解决思路----------------------
-- ================================================
-- Template generated from Template Explorer using:
-- Create Scalar Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
/*
SELECT dbo.FUN_IsNull(120.11)
*/
-- =============================================
CREATE FUNCTION FUN_IsNull
(
-- Add the parameters for the function here
@VALUE DECIMAL(18,2)
)
RETURNS DECIMAL
AS
BEGIN
-- Declare the return variable here
DECLARE @RetValue DECIMAL(18,2)
IF @VALUE > 100
SET @RetValue = 100
ELSE
SET @RetValue = @VALUE
RETURN @RetValue
END