Fill GridView with two nested tables

0

I have the following two nested tables:

TAREAS(
ID INT PRIMARY KEY,
TAREA VARCHAR(50),
DETALLES VARCHAR(200),
FECHAINICIO DATETIME,
FECHAFIN DATETIME);

TRABAJADORES_TAREAS(
ID INT PRIMARY KEY,
TAREA INT FOREIGN KEY REFERENCES TAREAS(ID),
TRABAJADOR INT FOREIGN KEY REFERENCES TRABAJADORES(ID)
);

TRABAJADORES(
ID INT PRIMARY KEY,
NOMBRE VARCHAR(100),
APELLIDO VARCHAR(100),
ESPECIALIDAD VARCHAR(100)
);

As you can see there may be many workers in the same task and each worker can have many tasks assigned. I want to show the data in a GridView, but I do not know how to make the records repeat or there is another control that helps me better.

GV-TRABAJADORES-TAREAS:

ID - TAREA - DETALLES - FECHA INICIO - FECHA FIN - TRABAJADORES

1  - tarea1 - bla bla - 01-11-17     - 02-11-17  - Adan Alvarez/Beto Beltran/...

Something like that I would like it to be displayed.

    
asked by Luis Pizarro Ramírez 08.11.2017 в 13:23
source

1 answer

0

You need to relate the tables through a union and generate a function that returns a list of workers

could look like this:

generate the following scalar type function

USE [Ejemplo]
GO
/****** Object:  UserDefinedFunction [dbo].[fn_ConcatenaMemo]    Script 
Date: 09/11/2017 12:45:44 a. m. ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER function [dbo].[fn_ConcatenaMemo] (@id int)
returns varchar(50)
as 
begin
declare @memo varchar(50)
set @memo = ''
select @memo = @memo + '  '+[dbo].[TRABAJADORES].[NOMBRE] from [dbo].
[TRABAJADORES]

return (@memo)
end

Now you just have to put this query

    select top 1 * ,[dbo].[fn_ConcatenaMemo](1)
from [dbo].[TRABAJADORES_TAREAS] 
inner join [dbo].[TAREAS] on [dbo].[TRABAJADORES_TAREAS].[TAREA]=[dbo].[TAREAS].[ID] 
inner join [dbo].[TRABAJADORES] on [dbo].[TRABAJADORES_TAREAS].[TRABAJADOR]=[dbo].[TRABAJADORES].[ID]
where [dbo].[TAREAS].[ID]=1

select [dbo].[fn_ConcatenaMemo](1)

hehe in the final query just select the fields you want and already, it will not happen to me as in the photo

    
answered by 09.11.2017 в 07:52