update columns when value is numeric in tsql
Posted
by knittl
on Stack Overflow
See other posts from Stack Overflow
or by knittl
Published on 2010-05-26T09:59:46Z
Indexed on
2010/05/26
10:01 UTC
Read the original article
Hit count: 283
i want to normalize date fields from an old badly designed db dump. i now need to update every row, where the datefield only contains the year.
update table set date = '01.01.' + date
where date like '____' and isnumeric(date) = 1 and date >= 1950
but this will not work, because sql does not do short circuit evaluation of boolean expressions. thus i get an error "error converting nvarchar '01.07.1989' to int"
is there a way to work around this? the column also contains strings with a length of 4, which are not numbers (????
, 5/96
, 70/8
, etc.) the table only has 60000 rows
© Stack Overflow or respective owner