set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER FUNCTION [dbo].[fun_Str](@SourceSql varchar(8000),@StrSeprate varchar(10)) RETURNS @temp TABLE(a varchar(100)) BEGIN DECLARE @i int SET @SourceSql=RTRIM(RTRIM(@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
以上是sql方法,
select b.*,a.weburl from UsedCar_SubSiteList a,UsedCar_FriendLink b where a.id in ( SELECT a FROM dbo.fun_Str(a.SubSiteIds ,',') )
表结构关系
SubSiteList(id,weburl)
FriendLink (id,name,subIds)
描述:subIds保存字段为格式为:1,2,3,4,5..;subIds保存了SubSiteList里面的id值;