-3

I am trying to clean my data on SQL. My sample data is below:

enter image description here

Could you please let me know how can I remove the date-time parts? Thanks,

https://docs.google.com/spreadsheets/d/1BvVxU0_a53vncGpd0Mbr57WPUbG89MgfpYGah0JBdIA/edit?usp=sharing

Dušan
  • 269
  • 1
  • 11

2 Answers2

0

You can use this regex for selecting date-times that you want to remove:

(\(?[0-9]{2}\/){2}([0-9]{4}\)?)

Then replace that part of string with blank space, which is the same as removing.

To see how to use replace method in SQL with regex check this answer.

Dušan
  • 269
  • 1
  • 11
0

SQL Server is not particularly good at string manipulations.

However, based on the examples in your question, the "cleaning" is either removing the first 11 characters or the last 13 characters, depending on where the date is. Fortunately, this is actually something you can do in SQL Server:

select t.*,
       (case when data like '% ([0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9])'
             then left(data, len(data) - 13)
             when data like '[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9] %'
             then stuff(data, 1, 11, '')
             else data
        end) as cleaned_data
from t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786