September 1, 2021 at 12:16 pm
Hi there, everyone.
I have an SSIS package where I have to write a large table to smaller csv files. I have created a stored procedure as below that is called by an OleDb Source inside a workflow task. This then needs to write each result to a file. I'm very confused as to how to do this. Below is the stored procedure. Can anyone steer me in the right direction as to how to approach this, please?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GEO_FileExtract]
AS
BEGIN TRY
DECLARE @TempTable TABLE (
[IDNO] [varchar](16) NULL,
[GEO001] [varchar](15) NULL,
[GEO002] [varchar](5) NULL,
[GEO003] [varchar](5) NULL,
[GEO004] [varchar](5) NULL,
[GEO005] [varchar](5) NULL)
WHILE EXISTS (
SELECT TOP 1 *
FROM dbo.GEO AS INXG
WHERE IsProcessed = 0)
BEGIN
INSERT INTO @TempTable (
IDNO,
GEO001,
GEO002,
GEO003,
GEO004,
GEO005)
SELECT TOP 50000
INXG.IDNO,
INXG.GEO001,
INXG.GEO002,
INXG.GEO003,
INXG.GEO004,
INXG.GEO005
FROM dbo.GEO AS INXG
ORDER BY INXG.IDNO
UPDATE INXG
SET IsProcessed = 1
FROM dbo.GEO AS INXG
JOIN @TempTable AS TT
ON INXG.IDNO = TT.IDNO
WHERE INXG.IsProcessed = 0
SELECT
IDNO AS IDENTIFIERNUMBER,
TT.GEO001 AS EACODEOFCONSUMER,
TT.GEO002 AS PROVINCEOFCONSUMER,
TT.GEO003 AS DISTRICTOFCONSUMER,
TT.GEO004 AS METROPOLITANOFCONSUMER,
TT.GEO005 AS MAINPLACEOFCONSUMER
FROM @TempTable AS TT
END
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_STATE() AS ErrorState,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH
September 1, 2021 at 12:58 pm
BCP aka Bulk Import/Export is 1 option
September 1, 2021 at 5:06 pm
I have a few quick comments.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 1, 2021 at 5:24 pm
Do you know the number of files (smaller files) to be created out of the table? Or it's dynamic?
September 1, 2021 at 7:08 pm
Hi there. Yes, it does include a where IsProcessed =! Or should. Seems I forgot to put it back. I’ll use a temp table instead. Thanks for the advice.
September 1, 2021 at 7:10 pm
Hi there, Brahmanand. The row count is dynamic as it changes. The max size per file should be around 100MB. This will be sent to Azure BLOB and copied to Snowflake.
September 3, 2021 at 1:27 pm
I recommend the following steps:
You can refer to the following articles for dividing a dataset into equal groups.
Divide the rows in equals batches
Divide the rows of a column in equals batches in grid format
September 3, 2021 at 3:01 pm
I misunderstood the requirement – you want to split the rows contained in the table across a number of files. My comment (5) therefore makes no sense whatsoever!
The method described above looks like it will work. Another possibility is that you output to a single large file and then run a process afterwards which splits that file into multiple files.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 4, 2021 at 6:40 am
Wow, awesome. Thank you!
September 6, 2021 at 11:52 am
This was removed by the editor as SPAM
September 21, 2021 at 10:28 am
This was removed by the editor as SPAM
September 21, 2021 at 1:58 pm
Thanks for this case. Very interesting solution!
Sounds like a typical generic post as a precursor to SPAM. "Santa is watching"!
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply