I have found many examples of how to remove things from strings. In this case I want to search a string for timestamps and add single quotes around each. So how to search this string:
and produce this result:
without knowing the exact text of the string, only knowing the format will match the timestamp format above. It is preferable to code this within a block of existing code rather than calling a separate function. What is the best way to handle this task? |
EDIT: Code corrected... The following code (now working - thanks to Elmi- see below) might be used to work with a list of unknown size and unknown position of any date/time/timestamp values. It makes use of the handy sa_split_list and isdate functions.
So you might treat this as a starting point at least... |
SELECT row_value AS Token, IF ISDATE ( row_value ) = 1 THEN 'Yes, a timestamp' ELSE 'No, something else' ENDIF AS YesNo FROM sa_split_list ( '2,,2010-11-04 10:13:45.805' ); Token,YesNo 2,'No, something else' ,'No, something else' 2010-11-04 10:13:45.805,'Yes, a timestamp' |
Lots of good information here. Thanks to all.