SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


IS IT POSSIBLE ?--NOT to CREATE Flat File If it is empty?


IS IT POSSIBLE ?--NOT to CREATE Flat File If it is empty?

Author
Message
Michael Earl-395764
Michael Earl-395764
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5197 Visits: 23078
Think from the other direction - if there were no rows, delete the file.

Get the rowcount during your data flow and put it into a variable. In the control flow of the package use a precedence constraint to check if the rowcount was zero - if it was, use a file system task to delete the file.
SSIS\SSRS\SSAS
SSIS\SSRS\SSAS
SSC Eights!
SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)

Group: General Forum Members
Points: 962 Visits: 530
Thanks Michael.........yet another way of doing it , more simple.
But now the problem is ( i would say not problem, but more complex) that i have seven flat files destination, then so i have to create 7 variable to hold rowcount for each file connection, i. e. 7 row count task with 7 variable and also agian 7 file system task to do delete.

Would n't it be possible that just loop over the folder to see if any file that exists has size 0 , then if so delete it. Now, here i have problem, i am nor good at coding VB. so i have to work hard to get some code..

ANyone out there can plzzzzzzz post me a code to see if any file in a folder has size 0 and if so delete it.

Thanks.........
Crispin Proctor
Crispin Proctor
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1553 Visits: 414
wow. Talk about many was to skin a cat. Some convoluted methods at that.

Just use a row count component, set the value to a variable, after your data flow, if value is zero, run script task and delete the file.

If you _really_ don't want to create the file, use a script component as a destination. Only create the file when you receive your first row.




Cheers,
Crispin


I can't die, there are too many people who still have to meet me!

It's not a bug, SQL just misunderstood me!
Chuck Rivel
Chuck Rivel
Right there with Babe
Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)

Group: General Forum Members
Points: 735 Visits: 357
if you want to go down the path of looping through a folder and checking file sizes, there are two steps to add to your package. (I like this idea, as you mentioned, because then you do not need the 7 variables and 7 script tasks)

First is add the for each loop container which uses the Foeach File Enumerator and returns the Fully Qualified path to a variable, which I setup as FilePath

Then, inside of the ForEach Loop, I have a script task with the following code (pass in the FilePath as a ReadOnly variable):

Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO


Public Class ScriptMain

Public Sub Main()
Try
Dim ofile As New FileInfo(Dts.Variables("FilePath").Value.ToString)

' Check size of file, if 0 then delete
If ofile.Length = 0 Then
File.Delete(Dts.Variables("FilePath").Value.ToString)
End If
Dts.TaskResult = Dts.Results.Success
Catch
Dts.TaskResult = Dts.Results.Success
End Try

End Sub

End Class
Crispin Proctor
Crispin Proctor
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1553 Visits: 414
While this is a perfectly valid solution if you don't want to use the variable / delete option, I would rather pass the folder to the script task and use a for each file in folder and delete like that. It would be far far quicker than SSIS looping and executing the script task. If of course you want to do other stuff before or after deleting then it is acceptable.



Chuck Rivel (8/12/2008)
if you want to go down the path of looping through a folder and checking file sizes, there are two steps to add to your package. (I like this idea, as you mentioned, because then you do not need the 7 variables and 7 script tasks)

First is add the for each loop container which uses the Foeach File Enumerator and returns the Fully Qualified path to a variable, which I setup as FilePath

Then, inside of the ForEach Loop, I have a script task with the following code (pass in the FilePath as a ReadOnly variable):

Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO


Public Class ScriptMain

Public Sub Main()
Try
Dim ofile As New FileInfo(Dts.Variables("FilePath").Value.ToString)

' Check size of file, if 0 then delete
If ofile.Length = 0 Then
File.Delete(Dts.Variables("FilePath").Value.ToString)
End If
Dts.TaskResult = Dts.Results.Success
Catch
Dts.TaskResult = Dts.Results.Success
End Try

End Sub

End Class





Cheers,
Crispin


I can't die, there are too many people who still have to meet me!

It's not a bug, SQL just misunderstood me!
SSIS\SSRS\SSAS
SSIS\SSRS\SSAS
SSC Eights!
SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)SSC Eights! (962 reputation)

Group: General Forum Members
Points: 962 Visits: 530
I belive Crispin is right too. But there will be only about 7 files each time i run and mostly one or two files will be empty. But agian we start using application later on , there won't be any file with 0 Kb. this is simplly for the initial stage of the apllication.
Thanks CHuck!!!! for the code.............

Really appreciate all the help and inputs..
thansk guys...............
ramkidec11
ramkidec11
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 53
thanks!!!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search