Replace always replacing null values

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-05-03T18:50:16Z Indexed on 2010/05/03 19:08 UTC
Read the original article Hit count: 181

Filed under:

Why does

left(FIELD, replace(nullif(charindex('-', FIELD), 0), null, len(FIELD)))

always return null? The idea behind the query is that if charindex() returns 0, then convert the results into null, then convert the null into the length of the field. So if '-' does not exist, show the whole string. For some reason it makes every row equal null.

Thank you.

© Stack Overflow or respective owner

Related posts about sql-server-2000