December 7, 2009 at 2:56 pm
Could someone explain to me why the following returns a double quote as the result?
Notice that the dollar value is in double quotation marks, declared as a varchar. I just find the result here to be somewhat confusing. Yes, I know I did it in the wrong order compared to what I intended to do...
declare @r varchar(255)
select @r = '"$5,176,641.00"'
select @r = replace('"','',@r)
select @r
December 7, 2009 at 3:46 pm
I think you answered your own question. The incorrect order of the REPLACE function parameters is the problem. You should run it like this instead:
select @r = replace(@r,'"','')
_________________________________
seth delconte
http://sqlkeys.com
December 7, 2009 at 4:07 pm
oh I know I am getting the wrong result. I messed that part up (since corrected in the ad-hoc code this was from). What I do not understand is why the result set is a double quote even in my wrong code.
December 7, 2009 at 4:29 pm
That's because in this syntax:
declare @r varchar(255)
select @r = '"$5,176,641.00"'
select @r = replace('"','',@r)
select @r
you are using a double-quote as the string expression, and trying to replace every instance of '' (nothing) with the string "$5,176,641.00". There are no any instances of nothing (empty string), so the string expression remains unchanged (the double-quote that you started with). Does that make sense?
_________________________________
seth delconte
http://sqlkeys.com
December 7, 2009 at 4:38 pm
Perfectly! I knew I was just missing one little detail in my thinking! Thanks.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply