Best method for varchar date validation in Sybase (T-SQL)?

Question :

Best method for varchar date validation in Sybase (T-SQL)?,

Answer :

I have a stored procedure which takes as its parameter a varchar which needs to be cast as a datetime for later use:

SET @the_date = CAST(@date_string AS DATETIME)  

I’m expecting the date string to be supplied in the format “DD-MON-YYYY”, but in an effort to code defensively, if for some reason it can’t be cast successfully, I want to default to the system date and continue. In PL/SQL I could use exception handling to achieve this and I could do this fairly easily with regular expressions too, but the limited pattern matching supported out of the box by Sybase doesn’t let me do this and I can’t rely on third party libraries or extensions. Is there a simple way of doing this in T-SQL?

Read More  Replicating load related crashes in non-production environments

NB: using Sybase ASE 12.5.3, there is no ISDATE function

,

I’m having a similar issue. You might be able to do something like this:

SET arithabort arith_overflow off  SET @the_date = CAST(@date_string AS DATETIME)  IF @the_date is NULL      set @the_date = getdate()  SET arithabort arith_overflow on  

However, this doesn’t work well in a select. It will work well in a cursor (boo) or in logic before / after a SQL batch.

That’s the answer Best method for varchar date validation in Sybase (T-SQL)?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Read More  Select all columns except one in MySQL?

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you