Salut,
Il existe certainement des fonctions pour faire ça, mais moi je l'ai fait à la main.
J'ai mis le code dans une fonction de table inline pour pouvoir l'appeler facilement.
Le table de retour contient une colonne compteur pour pouvoir extraire le champ de n'importe quelle position.
(table inline veut dire que c'est comme un tableau dans des language comme c++ ou c#)
-- APPEL DE LA FONCTION :
SELECT * FROM splitParBlanc('2000 = 3000 * 4005')
-- RESULTAT :
t_id t_str
-------------------
1 2000
2 =
3 3000
4 *
5 4005
-- LA FONCTION :
CREATE FUNCTION splitParBlanc
(
@strToSplit varchar(200)
)
RETURNS @tbl_array table(t_id int identity(1,1), t_str varchar(35))
AS
BEGIN
-- compteur boucle
DECLARE @i int
SET @i = charindex(' ', @strToSplit)
-- pour taille d'extraction
DECLARE @increment int
SET @increment = 0
WHILE( @i > 0 )
BEGIN
-- départ de l'extraction
DECLARE @start int
SET @start = charindex(' ', @strToSplit, @increment+1)
SET @start = @start - (@start - @increment)
-- pour calculer la taille de l'extraction
SET @increment = charindex(' ', @strToSplit, @start+1)
-- stocke valeur si champ non vide
IF( substring(@strToSplit, @start+1, @increment- @start-1) <> ' ' )
INSERT INTO @tbl_array(t_str)
SELECT substring(@strToSplit, @start+1, @increment- @start-1)
-- pour prochaine boucle ou fin
SET @i = charindex(' ', @strToSplit, @increment+1)
-- stocke le dernier bloc
IF( @i <= 0 )
INSERT INTO @tbl_array(t_str)
SELECT substring(@strToSplit, @start+(@increment- @start)+1, len(@strToSplit)-@start-1)
END
RETURN
END