C'est moyen utile et simple d'interroger une chaîne délimitée comme s'il s'agissait d'une table.
Extrait de: http://www.mindsdoor.net/SQLTsql/ParseCSVString.html
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_ParseCSVString]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_ParseCSVString]
GO
create function fn_ParseCSVString
(
@CSVString varchar(8000) ,
@Delimiter varchar(10)
)
returns @tbl table (s varchar(1000))
as
/*
select * from dbo.fn_ParseCSVString ('qwe,c,rew,c,wer', ',c,')
*/
begin
declare @i int ,
@j int
select @i = 1
while @i <= len(@CSVString)
begin
select @j = charindex(@Delimiter, @CSVString, @i)
if @j = 0
begin
select @j = len(@CSVString) + 1
end
insert @tbl select substring(@CSVString, @i, @j - @i)
select @i = @j + len(@Delimiter)
end
return
end
GO
Utilisez une fonction split. Vous pouvez voir un exemple dans ma réponse ici: http://stackoverflow.com/questions/7274514/sql-query-to-match-keywords –
ok, j'ai un peu de mal, parce que le mien est une chaîne d'entrée brute que le – Cavide
à droite, je regarde la table des nombres qui est où je trébuche – Cavide