0

I have a table like so

[filenameAndDate][DateCreated]

the first column looks like this "myvideo/12.12.2012" and the second column is empty

How would I write a sql query to extract the date from [filenameAndDate] and place it into the [DateCreated] column

D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
tama
  • 315
  • 2
  • 14

3 Answers3

2
UPDATE [dbo].[FileNames]
SET [DateCreated] = Convert(Date, 
   SUBSTRING(FileNameAndDate, CHARINDEX('/', FileNameAndDate, 0) + 1,
   LEN(fileNameAndDate)))

this is for MSSQL

JohnW
  • 326
  • 4
  • 9
1

You can try this, mate:

UPDATE
  <your_table>
SET
  DateCreated = RIGHT(filenameAndDate, 10)
WHERE
  filenameAndDate = 'myvideo/12.12.2012';  

Suggestion:

  • Maybe you can organize your table in a way it may not hurt an application based on the content of a field.

  • Another one is the format of the date you'll be using, it would be better if you use the yyyy-mm-dd format.

PS: this is for MySQL

Cheers!

Avidos
  • 739
  • 12
  • 23
0

Equivalent of explode() to work with strings in MySQL

then use it like

insert into blabla (col1, col2) value (val1, SPLIT_STRING(val1,'/',2));
Community
  • 1
  • 1
Ghean
  • 21
  • 7