I have a .sql file which includes lots of create function and other statements. I put go keyword between them but I got Incorrect Syntaxt Near Go
error when I run this by stmt.executeupdate() in java. But when I run it in SSMS 17 I do not get any error. For example here:
GO
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[calculateweekday]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' )) begin
DROP FUNCTION [dbo].[calculateweekday]
end
GO
create function [dbo].[calculateweekday]
(@inputDate datetime)
returns int as begin
Declare @result int;
Declare @tmp int
select @tmp = (select DATEPART(weekday, @inputDate))
if (@tmp != 1) begin
select @result = (select @tmp - 1)
end else begin
select @result = (select 7)
end
return @result
end
GO
I tried to put this in notepad++ too see if there is something wrong but it look likes same.
I also tried to change the encoding UTF-8 and ANSI but could not solve it. How can I solve this?