1
In the tabela_A own a field cod_canal where is a INT, in tabela_B own a field canais of the string type and separating the codes by ,.
Example: 1,3,6,9,12.
On a first attempt, I just thought I’d make the clause this way:
[...] WHERE tabela_A.cod_canal IN (tabela_B.canais) [...]
And obviously, I got the mistake:
SQL Error [245] [S0001]: Conversion failed when Converting the nvarchar value '0,1,3,5,9,12' to data type int.
com.microsoft.sqlserver.jdbc.Sqlserverexception: Conversion failed when Converting the nvarchar value '0,1,3,5,9,12' to data type int.
I tried to use the function PATINDEX, but I believe I have not understood the correct functioning of it and I do not have the expected result
AND PATINDEX('%' + CAST(tabela_A.cod_canal AS NVARCHAR) + '%', tabela_B.canais) > 0
How can I get the results from tabela_B from the relationship between the fields cod_canal and canais? Due to the difference in the type of data and formats inserted in the respective fields.
You will have to convert to an array of integers
– Marco Souza