I have a SQL command in crystal reports (its OK if your not familiar with crystal) and I need to convert a date parameter to a decimal (to match a column in the database.)
SELECT decimaldate FROM TABLE1 WHERE decimaldate = {?normaldate}
--ex: 12/01/2011 needs to become 12012011
IF I use a CAST on the above query it doesn't work:
SELECT decimaldate FROM TABLE1 WHERE decimaldate =
CAST(CAST{?normaldate} AS VARCHAR) AS DECIMAL)
I suggest creating a formula (called something like @decimaldate) in formula to hold the equivalent numeric value of your date paramter - so it would be something like:
- then amend your selection criteria to select based on your new formula - like so:
I think
VARCHAR_FORMAT()
is actually what you're looking for:You may have to wrap
@NormalDate
withDATE()
to cast it to a date type (it depends on your input format).Try something like this.
Or something like this where @normaldate is the search date.
This DB2 SQL function performs the date to MDY decimal conversion your query needs. Once it's created, your queries can compare a decimal column containing an MDY date to the output of UTIL.TO_DECIMAL_MDY( someValidDate )