Page 1 of 1

Help in constraint for Date validation

Posted: Sun Jan 22, 2012 3:23 am
by vskr72
I have the following recrods from a file. (I am showing only 1 colunmn for simplicity). I haev to perform a Date validation and if it fails, then I need to write it to a flat/reject file. The data is coming from a fixed with file. The constraint I have is like this:

Code: Select all

NOT(Isvalid ("date", Datecol,"%yyyy%mm%dd"))
Expectation is that this should be true only for a invalid date format. All the valid date formats and NULL should be skipped. SO only real invalid dates shodul go the reject file. I used TRIM and that was also not workign either. Any thoughts?

Re: Help in constraint for Date validation

Posted: Sun Jan 22, 2012 7:26 am
by vamsi.4a6
1)Define a stage variable
If Isvalid ("date", Datecol,"%yyyy%mm%dd") then 1 else 0-sv

2)Use constraint sv=0

Posted: Sun Jan 22, 2012 9:03 am
by chulett
vamsi.4a6 wrote:1)Define a stage variable
If Isvalid ("date", Datecol,"%yyyy%mm%dd") then 1 else 0-sv

2)Use constraint sv=0
A couple of learning points:

There really isn't any difference between the two posted approaches (other than one checks for true and the other false), so unless we know the why of the "not working" comment I doubt it will help. Also, there's no need for the if-then-else wrapper for the derivation, especially one that sets the output to 1 or 0. As shown in the original post, they will always derive "true" or "false" automagically, which also just so happens to be 1 (technically non-zero) and 0 under the covers.

So, having said that... vskr72, can you post actual examples of your incoming records? Can you also confirm the data type you are using for these 'date' fields? You also said you only showed us one column, can we assume you need to check multiple date fields and reject the record if any of them are invalid? If so, I'd be curious what your full constraint looks like.

Posted: Sun Jan 22, 2012 12:22 pm
by ray.wurlod
Handle nulls first.