Tuesday, July 7, 2015

[Wat] Be careful what you end a job step in \


Had a job step that kept failing, though it ran when I ran it from SSMS. Start with simple, work towards complex.  And when I compared my code to the job step, they kept mismatching!  After the third time...

Create a job step with this:

select 'a' --test with a slash \ in the middle
select 'b' --test with a slash at the end \
select 'c' --test with a slash then a space \
select 'd' --last test no slash
--which of these will combine
--burma shave

aka

USE [msdb]
GO
EXEC msdb.dbo.sp_update_jobstep @job_id=N'5c84930d-3c6c-4408-9792', @step_id=4 ,
        @command=N'select ''a'' --test with a slash \ in the middle
select ''b'' --test with a slash at the end \
select ''c'' --test with a slash then a space \
select ''d'' --last test no slash
--which of these will combine
--burma shave'
GO

No problem, right?  A, B, C.  Set it to save to a output file, save, and run.  Now open that output file.



Wait, WAT?  Where's the C?

Open up the job step again... lo and behold, it combined lines... and commented a statement out.






Moral of the story - never end a line in a job step with a slash.

No comments: