IF NOT EXISTS(SELECT * FROM TEMPDB..SYSOBJECTS WHERE NAME = '##TABELA')
CREATE TABLE ##TABELA ( CHEQUES VARCHAR(MAX))
DELETE FROM ##TABELA
DECLARE @CHEQUES VARCHAR(MAX), @LIMITADOR VARCHAR(30), @REFERENCIA VARCHAR(30)
SET @CHEQUES = '123, 456, 789, 987, 654, 321'
WHILE LEN(@CHEQUES) > 0 BEGIN
IF PATINDEX('%,%', @CHEQUES) > 0 BEGIN
SET @LIMITADOR = SUBSTRING(@CHEQUES, 0, PATINDEX('%,%', @CHEQUES))
INSERT INTO ##TABELA (CHEQUES) VALUES (LTRIM(@LIMITADOR))
SET @CHEQUES = SUBSTRING(@CHEQUES, LEN(@LIMITADOR + ',') + 1, LEN(@CHEQUES))
END ELSE BEGIN
SET @LIMITADOR = @CHEQUES
SET @CHEQUES = NULL
INSERT INTO ##TABELA (CHEQUES) VALUES (LTRIM(@LIMITADOR))
END
END
SELECT * FROM ##TABELA
CREATE TABLE ##TABELA ( CHEQUES VARCHAR(MAX))
DELETE FROM ##TABELA
DECLARE @CHEQUES VARCHAR(MAX), @LIMITADOR VARCHAR(30), @REFERENCIA VARCHAR(30)
SET @CHEQUES = '123, 456, 789, 987, 654, 321'
WHILE LEN(@CHEQUES) > 0 BEGIN
IF PATINDEX('%,%', @CHEQUES) > 0 BEGIN
SET @LIMITADOR = SUBSTRING(@CHEQUES, 0, PATINDEX('%,%', @CHEQUES))
INSERT INTO ##TABELA (CHEQUES) VALUES (LTRIM(@LIMITADOR))
SET @CHEQUES = SUBSTRING(@CHEQUES, LEN(@LIMITADOR + ',') + 1, LEN(@CHEQUES))
END ELSE BEGIN
SET @LIMITADOR = @CHEQUES
SET @CHEQUES = NULL
INSERT INTO ##TABELA (CHEQUES) VALUES (LTRIM(@LIMITADOR))
END
END
SELECT * FROM ##TABELA
Gostou? Comente e compartilhe.
0 Comentários