sqlleftjoin字符串要实现join字符串
select * FROM table1 as t1
right join (select '1,2,3,4,5'  as t) as tt on t1.Id=tt.t
则需要分割字符串为数组,以下为实现的分割字符串函数split
split函数及使⽤⽰例:
select * FROM table1 as t1
right join (select * from split('1,3,5',',')) as tt on t1.Id=tt.F1
split函数:
/*
获取字符串数组的 Table wwwblogs/xqhppt/p/4377757.html
*/
if exists (select 1 from sysobjects where id = object_id('split' ))
drop Function split
go
CREATE function split(
@SourceSql varchar (max),
@StrSeprate varchar (10)
)sql left join 多表连接
returns @temp table( F1 varchar (100))
as
begin
declare @i int
set @SourceSql =rtrim( ltrim(@SourceSql ))
set @i =charindex( @StrSeprate,@SourceSql )
while @i >=1
begin
insert @temp values(left( @SourceSql,@i -1))
set @SourceSql =substring( @SourceSql,@i +1, len(@SourceSql )-@i)
set @i =charindex( @StrSeprate,@SourceSql )
end
if @SourceSql <>''
insert @temp values( @SourceSql)
return
end
GO
FromUrl:wwwblogs/xuejianxiyang/p/7025929.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。