2
I have the following table:
The goal is to make, in SQL Server, a function Split (by ',') the column EixoX
where the TipoGrafico
is different from 'Stockchart'. That is, if the TipoGrafico
is different from 'Stockchart' that is where I should split the contents of the column EixoX
.
Does anyone have an idea how to do?
Thanks in advance :)
You want to replace when
TipoGrafico
is equal toStockChart
for the value ofEixoX
? That’s it?– rbz
@RBZ For example, when the Type is different from 'Stockchart', that’s where I should do the Split of the contents of the Eixox column :)
– Araújo
Is "split" already working? If so, edit the question and put your query.
– rbz
@RBZ No, this is because I still have to create the :/ function but to simplify I will leave the conditions to perform the Split: Select * from tbGraficoConsults Where Idconfigurationqueries = xxx and Typography <> 'Stockchart'
– Araújo
what version of your bank?
– Thiago Magalhães
@Thiagomagalhães is SQL Server 2014
– Araújo
Try it that way:
SELECT TipoGrafico, (CASE WHEN TipoGrafico <> 'StockChart' THEN STRING_SPLIT(EixoX, ',') ELSE EixoX END) EixoX_
FROM tabela
– rbz
Or that:
SELECT TipoGrafico, (CASE TipoGrafico WHEN 'StockChart' THEN EixoX 
 ELSE STRING_SPLIT(EixoX, ',') END) EixoX_ FROM tabela
– rbz
@RBZ unfortunately cannot execute this query, this error appears: "'STRING_SPLIT' is not a recognized built-in Function name.". I think it must be because the 2014 version does not have this built-in function :/
– Araújo
Yeah, you’re gonna have to create a function: Link1 , Link2
– rbz
@RBZ Thanks for the help, I’ll try :)
– Araújo
select will remain, changing only the
STRING_SPLIT
:SELECT TipoGrafico, (CASE TipoGrafico WHEN 'StockChart' THEN EixoX ELSE nomeFuncao(EixoX, ',') END) EixoX_ FROM tabela
.– rbz
STRING_SPLIT
is only available as of 2016 version of SQL Server, and the version that is being used according to the comment is 2014. There are several examples of functions to split on the internet, here one of them: how-to-split-comma-delimited-string– Ricardo Pontual
@Exact Ricardopunctual, unfortunately I am not able to use this function. Thanks for the help Ricardo :)
– Araújo
@Araújo In the article "Separating multi-valued text content (split string)" you find several "split" tips. Acesse https://portosql.wordpress.com/2019/01/27/separar-conteo-texto-multivalorado_string-split/
– José Diz