Can't Replace Blank Value on a NVARCHAR

  • I have an nvarchar column that has a bunch of blank values. When I run a replace command on it the blank values are not replaced. Not sure what the catch is as I'm sure it has something to do with it being nvarchar.

    select replace(Weight1,'','0') From tTable1

    That command yields a bunch of blank values however if I select from the table with a Where = '' clause a record set is returned with many rows.

  • from books on line

    string_pattern

    Is the substring to be found. string_pattern can be of a character or binary data type. string_pattern cannot be an empty string ('').

  • UDPATE T SET Weight1 = '0' from dbo.tTable1 WHERE Weight1 = ''

    Also it might be worth it to convert that column to an integer or decimal. Then keep the weigth type in a separate column (Kg, lbs...).

  • steveb. (1/7/2011)


    from books on line

    string_pattern

    Is the substring to be found. string_pattern can be of a character or binary data type. string_pattern cannot be an empty string ('').

    Or put another way. How do you find nothing in something? And where is it when you find it?

    :w00t:

  • steveb,

    Thanks for the reply. Well that explains it. My BOL doesn't say anything about that in the Replace String Function command explanation. Go figure.

  • Ninja's_RGR'us (1/7/2011)


    UDPATE T SET Weight1 = '0' from dbo.tTable1 WHERE Weight1 = ''

    Also it might be worth it to convert that column to an integer or decimal. Then keep the weigth type in a separate column (Kg, lbs...).

    Yeah I didn't design this table. It was done by a front end guy. This is a great example of why choosing the right datatype is so important. At least the weight type is in a separate column but everything is nvarchar - lol. Time to tidy up this mess. .

  • AVB (1/7/2011)


    Ninja's_RGR'us (1/7/2011)


    UDPATE T SET Weight1 = '0' from dbo.tTable1 WHERE Weight1 = ''

    Also it might be worth it to convert that column to an integer or decimal. Then keep the weigth type in a separate column (Kg, lbs...).

    Yeah I didn't design this table. It was done by a front end guy. This is a great example of why choosing the right datatype is so important. At least the weight type is in a separate column but everything is nvarchar - lol. Time to tidy up this mess. .

    Well assuming clean data, sql server will convert '' to 0 so there may not even be a need for the update.

  • AVB (1/7/2011)


    steveb,

    Thanks for the reply. Well that explains it. My BOL doesn't say anything about that in the Replace String Function command explanation. Go figure.

    no worries, its in the 2008r2 BOL but maybe they missed it out of 2000 version

  • yeah It's not clean b/c when I try to do some calculations on it it fails after I try converting it to a decimal or int. I have a function I wrote for removing non-numeric characters from data. I'll zip it through that! 🙂

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply