sqlserver 函数里并返回一个表格数据拼接的字符串
2014-11-05 20:29
239 查看
Create function [dbo].[GetChildWorkerExtension]
(
@ChildId int
)
returns nvarchar(100)
as
begin
declare @ret nvarchar(2000)
set @ret = ''
select @ret = @ret+';'+(case Relationship
when 1 then '父亲'
when 2 then '母亲'
when 3 then '爷爷'
when 4 then '奶奶'
when 5 then '姥姥'
when 6 then '姥爷'
else '其它' end)+':'+ Phone from GuardianInfo where ChildId=@ChildId and (Phone is not null or Phone!='')
set @ret = case when len(@ret)>0 then stuff(@ret,1,1,'') else @ret end
return @ret
end
(
@ChildId int
)
returns nvarchar(100)
as
begin
declare @ret nvarchar(2000)
set @ret = ''
select @ret = @ret+';'+(case Relationship
when 1 then '父亲'
when 2 then '母亲'
when 3 then '爷爷'
when 4 then '奶奶'
when 5 then '姥姥'
when 6 then '姥爷'
else '其它' end)+':'+ Phone from GuardianInfo where ChildId=@ChildId and (Phone is not null or Phone!='')
set @ret = case when len(@ret)>0 then stuff(@ret,1,1,'') else @ret end
return @ret
end
相关文章推荐
- SqlServer:根据指定分隔符,把传入字符串分隔处理后,返回数据表,函数功能类似.NET的string.Split()
- SQLSERVER 函数--把拼接的字符串按照拼接字符分成表数据
- SqlServer和Oracle从多行记录(数据集)中查询结果并拼接成一个字符串的SQL语句(纵表数据转成拼接的文本)
- SqlServer 将查询出的多行数据拼成一个字符串返回
- SqlServer 如何将查询出的多行数据拼成一个字符串返回
- 一个字符串参数(s)由字母(a-z,A-Z)组成, 且最大字符位数为40,要求写一个函数, 返回该参数中连续相同字母的最大个数及该字母,如果最大位数有多个,则返回第一个。例:字符串“aaaddxxxxddddxxxx”,返回值为:“x,4”。
- 写一个返回字符串长度的函数,函数里面不用局部变量,不能调用系统函数strlen
- 设计函数,参数为一个int值,返回此数字的16进制字符串。
- 计算机笔试题:写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整型的函数)
- SQL 表数据多行某一列拼接成一个字符串
- 编写一个函数将一个十六进制数的字符串参数转换成整数返回
- 统计一个长度为2的子字符串在另一个字符串中出现的次数.例如:假定输入的字符串为“asd asasdfg asd as zx67 asd mklo”,子字符串为“as”,函数返回值为6。
- SQL写的一个为数字补零返回补零后字符串的函数
- 写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整形的函数?)
- 给定一个字符串,里面用空格分开为多个(>=6)部分组合,如:01 02 03 04 05 06 07 …… 写一个函数返回任意6个组合的字符串: 输出格式实例: 01 02 03 04 05 06 0
- 6_8_5在order结构体中添加一个函数.该结构体返回一个格式化的字符串,以合适的值替换用尖括号扩起来的条目
- 函数用于把一个用逗号分隔的多个数据字符串变成一个表的一列
- sql自定义函数:SF_Split,根据指定的分割符,把一个字符串分割成若干条短数据
- SqlServer:一个返回指定日期所在月份的最大天数的标量值函数
- 远离html字符串拼接,返回干净的数据