Sample code for 30+ languages & platforms
SQL Server

Reassemble a Previously Split File

Demonstrates how to reassemble a previously split file.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @fac int
    EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Any type of file may be reassembled.  It doesn't matter if it's
    -- a binary file or a text file.
    DECLARE @reassembledFilename nvarchar(4000)
    SELECT @reassembledFilename = 'hamlet2.xml'

    DECLARE @partPrefix nvarchar(4000)
    SELECT @partPrefix = 'hamlet'
    DECLARE @partExtension nvarchar(4000)
    SELECT @partExtension = 'spl'
    DECLARE @srcDirPath nvarchar(4000)
    SELECT @srcDirPath = '.'

    -- Reassembles the original file from hamlet1.spl, hamlet2.spl, ...
    EXEC sp_OAMethod @fac, 'ReassembleFile', @success OUT, @srcDirPath, @partPrefix, @partExtension, @reassembledFilename

    IF @success = 1
      BEGIN

        PRINT 'Success.'
      END
    ELSE
      BEGIN
        EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
      END

    EXEC @hr = sp_OADestroy @fac


END
GO