January 7, 2011 at 6:57 am
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.
January 7, 2011 at 7:06 am
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 ('').
January 7, 2011 at 7:06 am
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...).
January 7, 2011 at 7:07 am
steveb. (1/7/2011)
from books on linestring_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:
January 7, 2011 at 7:13 am
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.
January 7, 2011 at 7:17 am
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. .
January 7, 2011 at 7:19 am
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.
January 7, 2011 at 7:20 am
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
January 7, 2011 at 7:24 am
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