I Have made a stored proc and i would like it to return true of false depending if the SQL statement is valid.
Create PROCEDURE [dbo].[CheckSQLStatement]
@SQL varchar(8000)
AS
SET NOEXEC ON
Exec @SQL
SET NOEXEC OFF
This i what i have so far, when the statement is valid, in the SQL Server management studio, the results are Command(s) completed successfully. and if the statement i invalid it returns an error message, EG Incorrect syntax near 'Selec'.
Firstly how can i return a Value True of false if statement is valid.
Secondly how can i return the invalid error message?
I was thinking something like:
Create PROCEDURE [dbo].[CheckSQLStatement]
@SQL varchar(8000),
@IsValid bit OUTPUT,
@text NVARCHAR(1000)OUTPUT
AS
SET NOEXEC ON
Exec @SQL
SET NOEXEC OFF
Select @Isvalid
Select @Text
But i don't know how to set thos values?
Is there a better method?
Any help would be appreciated, Thanks in advance.