I need to extract a specific text from a string in a table column (Log table) which is actually a date (InactivationDate) and there is a value after this in the string. I need to extract this date value and insert it into another column in another table where there is a column named InactivationDate.
You'll have to provide specific examples of the strings to be searched.
Otherwise, all we can do is point you to the documentation for string functions and wish you luck.
Okay, the Column name is LogRecordData which comes from a table named ContentLog. The Column LogRecordData starts and contains other texts including for e.g. 'InactivationDate: NULL -> 2023-12-20 07:55:29'. I need to extract the date portion after the text InactivationDate from here and insert it in to another column in another SQL table which has a column named InactivationDate. I hope this info is sufficient.
Yes, I do not need the NULL (sorry for not making it clear in my reply), just the date without apostrophe symbol as well. Can I try the query provided by you.
To help you troubleshoot that, I'd need to know the value that triggered the error. Most likely there are entries that have a -> character in them, but what comes afterward is not a valid date. The only thing I can recommend is to change CONVERT() to TRY_CONVERT() and when it fails, it will return NULL rather than cause an error.
such that you provide the structure of a test table and some meaningful data corresponding to your real data.
In this way it becomes feasible to investigate any errors you find because we would have a common environment on which to work.
I will try your query, but I want to know if it will work irrespective of the position of the Inactivation date text in the string, because it's not in the same position in all the column data so I wanted to confirm with you before I try this.