chrisb

Commander
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2018-10-15
09:05
589 views
I need an operation that can execute an MS SQL script that is in the following form. So operation that I've found errors out at "GO" -- it seems that it can only handle the basic SQL statements, and each statement needs to end with a semicolon. Note that this statements works no problem if I enter it into MS SQL Developer. Is there a way to mirror that behavior from OO?
SET DATEFORMAT ymd GO -- -- NOCOUNT on insert -- SET NOCOUNT ON GO -- Wrap in transaction -- BEGIN TRANSACTION BEGIN TRY -- ~1000 insert statements here -- CheckRowcount -- DECLARE @after_rc int SELECT @after_rc = COUNT(*) FROM Units.SD_FundDetails IF 8503<> @after_rc BEGIN IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION SELECT 'Incorrect number of rows in table Units.SD_FundDetails' RAISERROR('Incorrect number of rows in table Units.SD_FundDetails', 18, 1) END END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS ErrorNumber, ERROR_SEVERITY() AS ErrorSeverity, ERROR_STATE() as ErrorState, ERROR_PROCEDURE() as ErrorProcedure, ERROR_LINE() as ErrorLine, ERROR_MESSAGE() as ErrorMessage IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION RAISERROR('Insert failed - check above message', 18, 1) END CATCH IF @@TRANCOUNT > 0 COMMIT TRANSACTION GO -- -- Disable NOCOUNT on insert -- SET NOCOUNT OFF GO
1 Solution
Accepted Solutions
chrisb

Commander
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-02-14
13:40
I ended up using the operations that runs Windows CMD and then run the sqlcmd utility.
2 Replies


Admiral
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2018-10-15
11:39
Have you considered wrapping in a stored procedure?
Powershell may be an alternative
Powershell may be an alternative
chrisb

Commander
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-02-14
13:40
I ended up using the operations that runs Windows CMD and then run the sqlcmd utility.