存在值信息函數
表值函數實現:spa
--實現split功能 的函數 拆分 逗號分開的多個值
ALTER function [dbo].[f_split](@SourceSql varchar(8000),@StrSeprate varchar(10)) returns @temp table(Gid Nvarchar(4000)) 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
關聯表結合函數 實現:code
SELECT A.Gid FROM OrderDetail B CROSS APPLY dbo.f_split(B.MarketGids,',') AS A