sqlserver中编写自定义函数中的返回值问题
来源:互联网 发布:杭州城市骑行大数据 编辑:程序博客网 时间:2024/06/14 06:59
写了一个获取符号间隔字符串的函数,原先代码如下
CREATE FUNCTION funGetSubStr
(
-- Add the parameters for the function here
@StrParams nvarchar(4000),
@char char(1)=N'1'
)
RETURNS nvarchar(4000)
AS
BEGIN
declare --@str varchar(300),
@id varchar(3000),
@m int,
@n int
--set @str='a,b,c,d,e'
--set @m=CHARINDEX(',',@str)
--set @n=1
--WHILE @m>0
--BEGIN
-- set @id=substring(@str,@n,@m-@n)
-- print @id
-- set @n=@m+1
-- set @m=CHARINDEX(',',@str,@n)
--END
set @m=charindex(@char,@strparams)
set @n=1
if @m>0
begin
set @id=substring(@strparams,@m,@m-@n)
return @id
end
else
begin
return null
end
END
GO
sqlserver提示,函数最后一句必须是return语句,后改为如下
-- ================================================
-- 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
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION funGetSubStr
(
-- Add the parameters for the function here
@StrParams nvarchar(4000),
@char char(1)=N'1'
)
RETURNS nvarchar(4000)
AS
BEGIN
declare --@str varchar(300),
@id varchar(3000),
@m int,
@n int
--set @str='a,b,c,d,e'
--set @m=CHARINDEX(',',@str)
--set @n=1
--WHILE @m>0
--BEGIN
-- set @id=substring(@str,@n,@m-@n)
-- print @id
-- set @n=@m+1
-- set @m=CHARINDEX(',',@str,@n)
--END
set @m=charindex(@char,@strparams)
set @n=1
if @m>0
begin
set @id=substring(@strparams,@m,@m-@n)
end
else
begin
set @id=null
end
return @id
END
GO
通过。
- sqlserver中编写自定义函数中的返回值问题
- 在 Excel 中编写自定义函数——返回多个值
- SQLServer 2012自定义函数,返回查询结果
- 用C#编写SQLServer自定义函数
- 编写一个函数,返回整型数组中的第二大值
- 自定义函数中返回值为指针的问题(1)
- 自定义函数中返回值为指针类型的问题(2)
- 在SqlServer中用自定义函数返回动态表内容
- 在SqlServer中用自定义函数返回动态表内容
- sqlserver中自定义字符串拆分函数
- 第8课 Python自定义函数返回值:单返回值和多返回值问题
- Swift中函数返回多值问题
- string 中的 length函数 和size函数 返回值问题
- sqlserver中的函数(积累中)
- js中一个函数获取另一个函数返回值问题
- 弄清字符串函数中strcmp函数的返回值问题
- 自定义函数中返回表的例子
- hive中如何自定义编写UDF函数
- Windows下命令行下启动ORACLE服务
- c/c++语言小知识(持续更新)
- ActionScript3: Dynamic Class
- QwtPlotPanner
- Java基础知识——JNI入门介绍(下)
- sqlserver中编写自定义函数中的返回值问题
- .Net事件与委托
- 2011.09.20
- Android怎么区分一个动态库是否为prelink过的
- NSString NSMutableString字符串 用一个字符替换其中的某个字符 字符串
- 静态函数和类的静态函数
- 使用TimeDifference,实现两个时间变量的相减,得出秒间隔
- VNC Server config
- [转载]setsocketopt 的 SO_DONTROUTE和SO_BINDTODEVICE的深层次分析