Cross several ID's of a field with a table

0

Greetings I have the following problem:

Name of my tables: Table_1 and Table_2

Name of my fields: In my Table_1 I have a Column_X and in my Table_2 I have Column_1 (ID) and Column_2 (Detail)

In Column_X of Table_1 I have stored data of type string with numerical value separated by ',' eg: 1,3,4,5, x, ... the number of records is undefined

In Column_1 of Table_2 I have the ID (of type int) and Column_2 the Detail where I store the label that would have to appear when doing the cross or inner join.

I tried it with a INNER JOIN , but it only brings me a value of one eg:

SELECT

TD.Columna_2

FROM Tabla_1 T

INNER JOIN Tabla_2 TD ON T.Columna_X = TD.Columna_1

and the result is only the first Detail not all the details separated by commas as with the ID (numbers)

    
asked by Rodrigo 26.06.2018 в 22:16
source

1 answer

0

Like Carmen, I think this is not the best structure to relate tables, however, I would only modify the inner join of your query:

INNER JOIN Tabla_2 TD on cast(T.ColumnaX as nvarchar(max)) like '%,'+TD.Columna_1+',%'

I would just make sure that the Columna_X field starts and ends with a comma ","

    
answered by 27.06.2018 в 00:01