Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help understanding a replace statment

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2011-10-24 : 11:45:03
While working on a task at work I was looking at a SQL 2008 proc with a command I am not vary familare with, the replace command. I kind of have an idea of what is going on but was hoping someone could explain it a bit more to me. The line is foind in an update call and is:

ReferringCity = replace([ReferringCity],char(9),'')

From what I know it is taking the current value of REferringCity and replaceing "char(9)" with nothing ('') and then setting REferringCity to the new value. What I am not really sure on is what the char(9) is and is my though of what is happening correct?

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-24 : 11:49:00
ASCII Code 9 is TAB


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-24 : 11:50:36
CHAR(something) means the character corresponding to that ascii value. see full ascii character details below

http://www.asciitable.com/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-10-24 : 11:51:12
You are correct - but it replaces all charcters of that value in the string not just the first.

char(9) is the character value 9. Not sure what it is - 10 is a line feed and 13 a carriage return. You can look it up in the ascii character set.
Presumably you are getting those characters and it is causing an issue so they are being replaced.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2011-10-24 : 13:21:32
Thanks for the help everyone and the link to the ASCII table, that will be very helpfull in the feature.

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-24 : 13:40:34
quote:
Originally posted by Eagle_f90

Thanks for the help everyone and the link to the ASCII table, that will be very helpfull in the feature.

--
If I get used to envying others...
Those things about my self I pride will slowly fade away.
-Stellvia


wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -