这样的语句要怎么写呢?

来源:百度知道 编辑:UC知道 时间:2024/07/05 18:45:05
字段中保存的内容类似:“1|2|11|12|15|25” 而外部获取的是:1或是2或是11 。要查出 所有包含外部获取的值的数据 , 这样的语句要怎么写呢?
sql语句,asp.net vb 或 C# 这个也有差别吗?

用什么语言?

我写的一个SQL函数,参数(源串,分隔字符,返回第几个字符)
CREATE function Get_Divstring(@sSourstr nvarchar(4000),@sChar nvarchar(1),@iOutIndex int)returns nvarchar(300)
as
begin
declare @iCharIndex int,@iStrlen int
declare @i int,@sOut nvarchar(300)
set @sSourstr=ltrim(rtrim(@sSourstr))
set @iStrlen=len(@sSourstr)
set @i=1
set @iCharIndex=1
while @i<@iOutIndex
begin
set @iCharIndex=(select charindex(@sChar,@sSourstr))
set @sSourstr=right(@sSourstr,@iStrlen-@iCharIndex)
set @iStrlen=len(@sSourstr)
if charindex(@sChar,@sSourstr)=0
break
set @i=@i+1
end
if charindex(@sChar,@sSourstr)<>0
begin
set @sOut=left(@sSourstr,charindex(@sChar,@sSourstr)-1)
end
else
begin
if @i+1<@iOutIndex
set @sOut=''
else
set @sOut=@sSourstr
end
RETURN(@sOut)
end