chrisb Trusted Contributor.
Trusted Contributor.
371 views

Is there an OO operation that can execute an MS SQL script?

Jump to solution

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
Tags (2)
0 Likes
1 Solution

Accepted Solutions
chrisb Trusted Contributor.
Trusted Contributor.

Re: Is there an OO operation that can execute an MS SQL script?

Jump to solution

I ended up using the operations that runs Windows CMD and then run the sqlcmd utility.

2 Replies
Outstanding Contributor.. JarodMB Outstanding Contributor..
Outstanding Contributor..

Re: Is there an OO operation that can execute an MS SQL script?

Jump to solution
Have you considered wrapping in a stored procedure?

Powershell may be an alternative
chrisb Trusted Contributor.
Trusted Contributor.

Re: Is there an OO operation that can execute an MS SQL script?

Jump to solution

I ended up using the operations that runs Windows CMD and then run the sqlcmd utility.

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.