34,594
社区成员
发帖
与我相关
我的任务
分享
L
create table ceshi(CompPhotos varchar(255),CompLinks varchar(255))
insert into ceshi(CompPhotos,CompLinks)
values('/Upload/CompanyTemplete/flashing/38/38_1.jpg|/Upload/CompanyTemplete/flashing/38/38_3.jpg|',
'www.baidu.com|www.youku.com|')
--
CompPhotos CompLinks
---------------------------------------------------------------------------------------------------------------/Upload/CompanyTemplete/flashing/38/38_3.jpg| www.baidu.com|www.youku.com|
(1 行受影响)
--
create table ceshi(CompPhotos varchar(255),CompLinks varchar(255))
insert into ceshi(CompPhotos,CompLinks)
values('/Upload/CompanyTemplete/flashing/38/38_1.jpg|/Upload/CompanyTemplete/flashing/38/38_3.jpg|',
'www.baidu.com|www.youku.com|')
go
create function getstr(@a varchar(1000),@b varchar(1000),@index int)
returns varchar(max)
as
begin
declare @str1 varchar(500),@str varchar(500),@no int
set @str = @a + '^' + @b
set @str1=''
set @no=1
while 1=1
begin
if(@no<@index)
begin
set @str1=@str1+left(@str,charindex('|',@str))
set @str=right(@str,len(@str)-charindex('|',@str))
end
else
begin
set @str=right(@str,len(@str)-charindex('|',@str))
break
end
set @no=@no+1
end
return @str1+@str
end
go
declare @i int
set @i = 1
;with t as
(
select dbo.getstr(CompPhotos,CompLinks,@i)st
from ceshi
)
select substring(st,1,charindex('^',st) - 1)CompPhotos,
substring(st,charindex('^',st) + 1,len(st) - charindex('^',st))CompLinks
from t
drop function getstr
drop table ceshi
CompPhotos CompLinks
---------------------------------------------------------------------------------------------------
/Upload/CompanyTemplete/flashing/38/38_3.jpg| www.baidu.com|www.youku.com|
(1 行受影响)
L
declare @index int
set @index=2
if @index=1
begin
select replace(CompPhotos,substring(CompPhotos,1,charindex('|',CompPhotos)),''),replace(CompLinks,substring(CompLinks,1,charindex('|',CompLinks)),'') from ceshi
end
if @index=2
begin
select replace(CompPhotos,substring(CompPhotos,charindex('|',CompPhotos),len(CompPhotos)),''),replace(CompLinks,substring(CompLinks,charindex('|',CompLinks),len(CompLinks)),'') from ceshi
end
create function getstr(@str varchar(1000),@index int)
returns varchar(max)
as
begin
declare @str1 varchar(500),@no int
set @str1=''
set @no=1
while 1=1
begin
if(@no<@index)
begin
set @str1=@str1+left(@str,charindex('|',@str))
set @str=right(@str,len(@str)-charindex('|',@str))
end
else
begin
set @str=right(@str,len(@str)-charindex('|',@str))
break
end
set @no=@no+1
end
return @str1+@str
end
create table ceshi(CompPhotos varchar(255),CompLinks varchar(255))
insert into ceshi(CompPhotos,CompLinks)
values('/Upload/CompanyTemplete/flashing/38/38_1.jpg|/Upload/CompanyTemplete/flashing/38/38_3.jpg|',
'www.baidu.com|www.youku.com|')
select dbo.getstr(CompPhotos,1),dbo.getstr(CompLinks,2) from ceshi
/*
---------------------------------------------------- -----------------
/Upload/CompanyTemplete/flashing/38/38_3.jpg| www.baidu.com|