I want to return the result of sql dynamic in stored procedure. This Stored Procedure is used in entity framework, when I try to create a complex type the procedure returns no columns. Is there any way I can force it to return my values and get the entity framework to receive them? Here is my stored procedure:
CREATE PROCEDURE [dbo].[SP_Check_Alarme]
(
@IdUser varchar (50)
)
AS
BEGIN
DECLARE @CMD as varchar(1000)
SET @cmd='SELECT MAG_Import_' + @IdUser +'.IdElement
,MAG_Import_' + @IdUser +'.Code
,MAG_Import_' + @IdUser +'.Surface
,MAG_Import_' + @IdUser +'.Lieu
,MAG_Import_' + @IdUser +'.Adresse
,MAG_Import_' + @IdUser +'.CodePostal
,MAG_Import_' + @IdUser +'.Ville
,MAG_Import_' + @IdUser +'.IdEnseigne
,MAG_Import_' + @IdUser +'.LibMagasin
,MAG_Import_' + @IdUser +'.TelStandard
,MAG_Import_' + @IdUser +'.IdClient
,MAG_Import_' + @IdUser +'.Warning
,MAG_Import_' + @IdUser +'.Alarme
,MAG_Import_' + @IdUser +'.DateCreation
,MAG_Import_' + @IdUser +'.AcrCreateur
,MAG_Magasin.IdMagasin
FROM MAG_Import_' + @IdUser +'
LEFT JOIN MAG_Magasin
ON replace(replace(MAG_Import_' + @IdUser +'.Adresse,char(10),'' ''),char(13),'' '') = replace(replace(MAG_Magasin.Adresse,char(10),'' ''),char(13),'' '')
AND replace(replace(MAG_Import_' + @IdUser +'.Lieu,char(10),'' ''),char(13),'' '') = replace(replace(MAG_Magasin.Lieu,char(10),'' ''),char(13),'' '')
AND MAG_Import_' + @IdUser +'.CodePostal = MAG_Magasin.CodePostal
AND (MAG_Magasin.Suppression IS NULL
OR MAG_Magasin.Suppression = 0)'
EXEC(@cmd)
END
GO