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


How to Check whether the filename is todays file or not(filename like CLM_2014050).


How to Check whether the filename is todays file or not(filename like CLM_2014050).

Author
Message
naresh0407
naresh0407
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 30
Hi All,

I have file name like this CLM_20140504.I will get file everyday..I just need to check whether file is today's file and then process it.Please let me know how we can do this.

CLM will be common and date should be today's date.tomorrow file name will be CLM_20140604.I need to compare current date with filename date i.e 20140504.







Thanks
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18622 Visits: 20449
naresh0407 (4/5/2014)
Hi All,

I have file name like this CLM_20140504.I will get file everyday..I just need to check whether file is today's file and then process it.Please let me know how we can do this.

CLM will be common and date should be today's date.tomorrow file name will be CLM_20140604.I need to compare current date with filename date i.e 20140504.

Thanks


The standard way of doing this is to archive the file to a different folder after processing it.

So your import (or whatever) just processes what is in the 'infiles' folder, regardless of its name.

One of the problems with your proposed method is what to do if the server is down for a day - you have to mess about forcing yesterday's file to be processed.

Another problem you will get is that the number of files in the folder builds up over time and you'll never be sure that all of them have been processed.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
naresh0407
naresh0407
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 30
Thanks for the reply..Just need to validate the filename CLM_20140504..Could you please let me know how can we validate.Today date is 20140504 so the CLM_20140504 is valid file.

File name should be with today's date.

If the file name is CLM_20140404 then this is yesterday's file so not valid.So we cannot process yesterday's file today since date in the file 20140404.
Eirikur Eiriksson
Eirikur Eiriksson
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15232 Visits: 18607
naresh0407 (4/5/2014)
.Just need to validate the filename CLM_20140504..Could you please let me know how can we validate.Today date is 20140504 so the CLM_20140504 is valid file.


Assuming that you have gotten the file name in a variable, then split it (remove the prefix) in an expression to retain the date part. Use an execute sql task to run this code on the sql server
select convert(varchar(32),getdate(),112)


and compare the two.
Cool
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