1
I’m having a problem with my script.
Context: I need to get information from a string that is in the nm_content column, but all the functions I try are not working. I tried to do it separately and it only works with a row, when I add a column, it gives error. Follow the command I tried
select top(1000) nm_retorno as teste
CASE WHEN nm_retorno LIKE '% id_revenda %'
THEN SUBSTRING(nm_retorno, (len(nm_retorno) - CHARINDEX(REVERSE('id_revenda'), REVERSE(nm_retorno)) + 12), len(nm_retorno))
ELSE nm_retorno
END as TesteRevenda
from Tabela
I tried some other ways but was unsuccessful. The error that appears is
Message 156, Level 15, Status 1, Line 2 Incorrect syntax near the keyword 'CASE'.
I also tried the following script and gave error
select top(1000) CASE WHEN nm_retorno LIKE '% ID_REVENDA=" %'
THEN SUBSTRING(nm_retorno, (len(nm_retorno) - CHARINDEX(REVERSE('ID_REVENDA="'), REVERSE(nm_retorno)) + 12), len(nm_retorno))
ELSE nm_retorno
END as TesteRevenda
from Tabela
Returns the following error:
Message 8116, Level 16, Status 1, Line 1 Argument data type text is invalid for argument 1 of Len Function.
Grateful from now on!
Your first command is not missing a
,
before CASE?– anonimo
Even with the comma the error persists
– Lucas Rossini
The syntax error? By the way it is Mysql or SQL Server?
– anonimo
It is SQL Server itself
– Lucas Rossini
If my answer helped you, please choose with the answer so that we can help others too! I gave a Up here for you;
– Mauro Rocha