把 下列的字符串
测试文件1,测试2,测试件3,
转成下面的3行测试文件1
测试2
测试件3
的一个函数!
测试文件1,测试2,测试件3,
转成下面的3行测试文件1
测试2
测试件3
的一个函数!
解决方案 »
- 请推荐基本学习SQL 2000或SQL 2005比较好点的书
- 求寫一個觸發器
- SQL中视图的使用问题
- 关于Sql Server2000 恢复数据的问题
- 请问哪里有SQL开发版下载?我要的是英文或繁体版
- sos 在线等待
- 如何设置delete的权限??????????????????????
- 在SQL SERVER 2000中怎样取得SQL执行出错后的错误信息?
- 急 这样的错误怎样解决? 是什么原因呢? 在线给分!!!!!!!!!!!!!
- 看着数据库板块(VFP)的不景气,实在是伤心,开个贴子放放分,希望数据版越来越红火,也借此向大家拜个早年,祝大家 新年快乐!事事顺心!……
- 我是初学者,一个SQL的简单问题!
- 求一SQL语句,关于按天数分组的
declare @tb table
(
F1 varchar(8000)
)
declare @str varchar(8000),@st1 varchar(8000),@I int
select @str='测试文件1,测试2,测试件3,'
select @I=charindex(',',@str)
while @I > 0
begin
insert into @tb
select substring(@str,1,@I-1)
select @str=substring(@str,@I+1,8000)
select @I=charindex(',',@str)
end
select * from @tb
/*
F1
-------
测试文件1
测试2
测试件3
*/
insert #t
select '测试文件1,测试2,测试件3,' declare @sql varchar(8000)
set @sql = ''
select @sql = replace(field,',',''' union all select ''') from #t
set @sql = 'select '' ' + REVERSE(stuff(REVERSE(@sql),3,16,'')) set @sql = REVERSE(stuff(REVERSE(@sql),1,1,''))
print @sql
exec(@sql)drop table #t
returns @t table(a nvarchar(100))
as
begin
set @a=@a+','
while charindex(',',@a)>0
begin
insert @t select left(@a,charindex(',',@a)-1)
set @a=right(@a,len(@a)-charindex(',',@a))
end
return
end
goselect * from dbo.fun_getStr('测试文件1,测试2,测试件3')
returns @tb table(col varchar(100))
as
begin
declare @t table(id int identity,b bit)
insert @t select top 100 0 from syscolumns a,syscolumns b
insert @tb select substring(@s,id,charindex(@split,@s+@split,id)-id)
from @t
where id<=len(@s+'!') and charindex(@split,@split+@s,id)=id
return
end
go
select * from dbo.f_splitStr('测试文件1,测试2,测试件3',',')
drop function f_splitStrcol
----------
测试文件1
测试2
测试件3