I need to create a procedure that creates a new table from the selection of one or several entities. The selection of 'IdEntity' I do from a gridView in the presentation layer in Visual Studio.
What I have is this:
CREATE PROCEDURE [dbo].[sp_LlenarRecursosEntidades]
@IdEntidad int
AS
BEGIN
declare @_identidad int = -1
if @IdEntidad is null set @IdEntidad = @_identidad
select E.IdEntidad, E.NombreEntidad from Entidad E
where E.IdEntidad = @IdEntidad
if object_id ('Resources') is not null
drop table Resources
begin try
select distinct E.IdEntidad as ResourceID, E.NombreEntidad as ResourceName
into Resources
from Entidad E
where E.IdEntidad = @IdEntidad
order by NombreEntidad
end try
begin catch
return -1
end catch
END
The problem is that the table stores only one entity when my code passed the 'IdEntity' of several Entities.
Clarifications
In my DB I have the Entity table (EntityID "int", EntityName "varchar")