Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Export data to flat file based on field once. Expand / Collapse
Author
Message
Posted Monday, April 15, 2013 6:26 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 15, 2014 5:59 AM
Points: 45, Visits: 342
Hi all,

I have a table that is selecting all the fields from the table and exporting to flat file in SSIS. One of the field in the table "Sent" is set to "0" by default. So when the SSIS package runs the query will set the field "Sent to "1" before moving the data to flat file. My question is how should I enforce the SSIS process to not send the data again after the field is set to 1. The process should only move the data to flat file once based on the "Sent" field. If the SSIS process runs again it should either fail or run with no data move to file.Please reply if anyone know regarding this.

Thanks.
Post #1442548
Posted Tuesday, April 16, 2013 12:29 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, December 18, 2014 11:42 PM
Points: 1,310, Visits: 1,786
I might not totally understand the requirements here, but couldnt you just use a TSQL task to import the dataset where it only grabs data where SENT = 0.
eg. SELECT col1, col2, col3 FROM table WHERE sent = 0

Then in the next task, export to flat file.

Then the next task update sent = 1, however that would be assuming no changes could be made to the input table by other processes during the export process. Otherwise you'll need a 'for each loop' container to run through each row in the resultset from the first task, updating sent = 1 based on the primary key. The loop can be linked to the first tsql task and the export task in the control flow so that the update only occurs after successfully writing to the flat file.
Post #1442609
Posted Tuesday, April 16, 2013 6:35 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 15, 2014 5:59 AM
Points: 45, Visits: 342
There is other process that just insert data to this table where 'Sent' column is '0' when other process insert data to the table. Then from their I have to pull data from the table e.g Select col1, col2,col3 from table where 'Sent' = 0. I didn't understand clearly, you said in first sql task Select col1, col2,col3 from table where 'Sent' = 0. then in second step use data flow task? Where should I update the column 'Sent' = 1? Is this before moving the data to flat file? How to write this? Also, if I run the process again with same data that update the column ' Sent' = 1, is this going to create file with same data again or not? If it is not then that will be right. Please reply.

Thanks,
Post #1442708
Posted Thursday, April 18, 2013 9:25 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, August 8, 2013 7:16 PM
Points: 221, Visits: 132
How often is data written into this table? Is it on a schedule? This might help determine how you would deal with exporting/updating the data.

--------
For SQL Tips, check out my blog: http://lantztechknowledge.blogspot.com/
You can also follow my twitter account to get daily updates: @BLantz2455
Post #1444217
Posted Friday, April 19, 2013 8:05 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 15, 2014 5:59 AM
Points: 45, Visits: 342
Data runs on a daily basis from different processes which insert the data into the table.Yes, it runs every morning as schedule. once it is insert into this table the 'IsSent' by default set the data to '0'. From there, it will pulls out from the table and write to a flat file. As it pulls out the field 'IsSent' set to '1'. So,I want only the data which set to 1 should pull out from the table.With that means, if there is data already pulled out before. I don't that to pull again with the new data.
Post #1444664
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse