MS SQL, Cómo ALTERAR/ CREAR procedimiento con error
Frecuentes
Visto 47 equipos
0
I need create procedure with contain errors. For example
CREATE PROCEDURE dbo.test
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM openquery(LINKED, 'select * from something'' ')
END
GO
Could not find server 'LINKED' in sys.servers
How can I created it though any errors (Not exists linkedserver or select in openquery return error) ?
1 Respuestas
0
You can use dynamic SQL to avoid linked server validation. Now you'll get the linked server error on execution instead of compilation. I personally think dynamic SQL is not an elegant solution, but it solves your problem.
CREATE PROCEDURE dbo.test
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sqlCommand NVARCHAR(MAX);
SET @sqlCommand = 'SELECT *
FROM openquery(LINKED, ''select * from something'''' '')';
EXEC (@sqlCommand)
END
GO
Respondido el 12 de junio de 14 a las 10:06
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas sql sql-server or haz tu propia pregunta.