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 2000 Forums
 Transact-SQL (2000)
 sql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-26 : 11:30:50
Marcus writes "Dear,

How can I change the first 4 positions of a row? I tried something:

replace test with '9999' for substr(test,1,4)='1111'

But this will change the whole row with 9999. Can you help me?

Thanks a lot!

Marcus"

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-04-26 : 11:46:29
DECLARE @MyString VARCHAR(100)
SET @MyString = '1111234567890987654321'

SELECT '9999' + RIGHT(@MyString, LEN(@Mystring) - 4)

Duane.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-04-26 : 11:48:42
[code]
DECLARE @x varchar(10)
SELECT @x = '9999876543'
SELECT REPLACE(SUBSTRING(@x,1,4),'9999','1111')+SUBSTRING(@x,4,LEN(@x)-3)

[/code]



Brett

8-)
Go to Top of Page
   

- Advertisement -