IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[checksyntax]') AND type = 'FN')
DROP FUNCTION [dbo].[checksyntax]
GO
create function [dbo].[checksyntax](
@source nvarchar(max),
@key1 nvarchar(100),
@key2 nvarchar(100),
@key3 nvarchar(100)
) 
RETURNS int
begin
declare @re int = 0 
set @key1 = ISNULL(@key1,'') 
set @key2 = ISNULL(@key2,'') 
set @key3 = ISNULL(@key3,'') 
set @source = LOWER(@source) 
set @key1 = LOWER(@key1) 
set @key2 = LOWER(@key2) 
set @key3 = LOWER(@key3) 

declare @i int 
set @i = CHARINDEX(@key1,@source) 
if (@i>0) 
begin
if (@key2<='') 
begin
set @re=0 
end else 
begin
set @source = SUBSTRING(@source , @i + len(@key1) , len(@source)-@i - LEN(@key1) + 2 ) 
set @i = CHARINDEX(@key2,@source) 
if (@i>0) 
begin
if (@key3<='') 
begin
set @re=0 
end else 
begin
set @source = SUBSTRING(@source , @i + len(@key2) , len(@source)-@i - LEN(@key2) + 2 ) 
set @i = CHARINDEX(@key3,@source) 
if (@i>0) 
begin
set @re=0 
end else
begin
set @re=1 
end 
end 
end else 
begin
set @re=1 
end 
end 
end else 
begin
set @re=1 
end 

return @re
end