1

Background on the problem: I've got MSSQL running in a Docker container, and I'm executing SQL scripts from a file within the container using Python/SQLAlchemy. I know this works because I've been executing other scripts without any problem. But one particular SQL script is executing without any result, and after careful elimination it seems to be caused by a single block of commented out code. Again this doesn't seem to cause an issue elsewhere, and the SQL script also runs faultlessly when executed directly in MSSQL.

The code that calls the SQL script:

with engine.connect() as con:
            with open(file_loc) as file:
                a = file.read()
                a = re.split('\nGO|\nGO\n|\ngo|\ngo\n', a) # split the query at GO
                for q in a:
                    con.execute(sa.text(q))

The code that causes the issue:

-- create new PMT() function
create function [financials].[pmt] (
   @r decimal(38,16)
) returns decimal(24,4)
as
begin
   declare @pmt decimal(24,4);
   ...
   return @pmt;
end;
GO
------ present value <<<<ANY COMMENT HERE PREVENTS THE FUNCTIONS FROM BEING CREATED
create function [financials].[pmt_PV] (
   @pmt decimal(38,16) <<removed trailing comma here
) returns decimal(24,4)
as
begin
   declare @pmt_pv decimal(24,4);
   ...
   return @pmt_pv;
end;
GO

Any comment in the the space marked in the middle prevents the functions from being created.

8
  • My assumption would be that the database engine does not see linefeeds and therefore the actual "end of line" for the comment is the end of the batch. Does it work if you change the comment to use /* and */ ? Commented Jul 14, 2022 at 12:14
  • @AlwaysLearning Sorry, my bad, I removed it. The function has more variables, but I edited them out because it's not my code and didn't want to share more than I needed. There's no trailing commas in the full function Commented Jul 14, 2022 at 12:37
  • @SMor Just tried the block comment and it didn't change anything Commented Jul 14, 2022 at 12:39
  • I am unable to reproduce your issue; this code works for me. Do you get an error message? Commented Jul 14, 2022 at 14:04
  • Does the comment have GO in it? Commented Jul 14, 2022 at 14:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.