April 8, 2010 at 2:56 pm
DECLARE @MYSTRING NVARCHAR(100)
SET @MYSTRING = 'MY VALUE 000 CHANGE'
I need to update a value in a database from
'MY VALUE 000 CHANGE'
'MY VALUE A1000 CHANGE'
What function should i use the charindex
UPDATE TABLE
SET COLUMN = @MYSTRING (Needs to have 'MY VALUE A1000') CHANGE)
WHERE COLUMN = @MYSTRING (Need to change 'MY VALUE 000 CHANGE' to 'MY VALUE A1000 CHANGE'
The values would be given to be as change
00000 to A10000
00001 to C10000
I would not know what position of the text it is..could be postion 14 or could be 70.
Any ideas
April 8, 2010 at 3:06 pm
Update Table
Set Column = REPLACE(Column, '00000', 'A10000')
Where (CHARINDEX('00000', Column, 1) > 0);
Update Table
Set Column = REPLACE(Column, '00001', 'C10000')
Where (CHARINDEX('00001', Column, 1) > 0);
April 8, 2010 at 7:03 pm
Worked a treat and replaced it anywhere it found it in the string.
Thank you so much got a hugh update to do.
What does the 1 mean ?
(CHARINDEX('00001', column, 1)
April 8, 2010 at 7:38 pm
TRACEY-320982 (4/8/2010)
Worked a treat and replaced it anywhere it found it in the string.Thank you so much got a hugh update to do.
What does the 1 mean ?
(CHARINDEX('00001', column, 1)
http://www.lmgtfy.com/?q=charindex+sql+server+2005
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 8, 2010 at 8:36 pm
TRACEY-320982 (4/8/2010)
Worked a treat and replaced it anywhere it found it in the string.Thank you so much got a hugh update to do.
What does the 1 mean ?
(CHARINDEX('00001', column, 1)
My recommendation is that you read about it in Books Online (the help system that comes with SQL Server) because the operand where the "1" is is very useful.
My other recommendation is that you read about all of the functions in SQL Server because, as with any other language, more than half the ability to solve a problem in a given languge comes from its functions.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply