SQL Data transformation statement (replace 0s with 1s inside in a nvarchar)

Viewed 22

I need to replace the 0's with 1's inside a string so that I can convert these values to DATE format. Let's say we have this data:

22010500
01010101
01010101
09030975
01010101

I would like the output to be:

22011500 -- (22-01-1500)
01011101 -- (01-01-1101)
01011101 -- (01-01-1101)
09031975 -- (09-03-1975)
01011101 -- (01-01-1101)

Can you help me with a sql statament to transform the data this way?

Thanks :)

1 Answers

We can use STUFF here:

UPDATE yourTable
SET date_col = STUFF(date_col, 5, 1, '1');
Related