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
 General SQL Server Forums
 New to SQL Server Programming
 Help with one function or procedure or trgger

Author  Topic 

spawn1986
Starting Member

4 Posts

Posted - 2010-03-10 : 13:40:52
Hi all, it's my first time here, but well, i need a solution for my problem, the problem is that i want to do a funtion to change a char in a string for example

i have this string 220440, and i need to replace 0 for nothing but only the 0 in the midle

please help with this problem

Informatic

spawn1986
Starting Member

4 Posts

Posted - 2010-03-10 : 13:50:09
please someone help me the database is in sqlserver please help me

Informatic
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-10 : 13:52:14
hint use CHARINDEX and SUBSTRING functions

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

Go to Top of Page

spawn1986
Starting Member

4 Posts

Posted - 2010-03-10 : 14:15:27
ok do you know what is the structure of update with this method i dont know a lot sql programming please help

Informatic
Go to Top of Page

CSears
Starting Member

39 Posts

Posted - 2010-03-10 : 16:09:35
LEN(@SourceString)

will be helpful as well in verifying that you aren't taking off the last digit.

http://msdn.microsoft.com/en-us/library/ms186323.aspx
This is the URL for the CHARINDEX Function, you can look up the other 2 there as well to find out how to use them properly. :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-10 : 16:29:36
What's about 220400 ?
What are the rules to replace a 0 by nothing?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

CSears
Starting Member

39 Posts

Posted - 2010-03-10 : 16:42:44
SET @VALUE = SUBSTRING(@VALUE, 1, 1) + REPLACE(SUBSTRING(@VALUE, 2, LEN(@VALUE)-2), '0', '') + SUBSTRING(@Value, LEN(@VALUE), 1)

First Char
SUBSTRING(@VALUE, 1, 1)

Midsection with the replace statement being used to remove the value
REPLACE(SUBSTRING(@VALUE, 2, LEN(@VALUE)-2), '0', '')

Last Char
SUBSTRING(@Value, LEN(@VALUE), 1)
Go to Top of Page

spawn1986
Starting Member

4 Posts

Posted - 2010-03-11 : 21:55:31
thanks for all i'll go to do that thanks

Informatic
Go to Top of Page
   

- Advertisement -