Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2007, 10:45 PM
Authorized User
 
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replace character

Hi I have data in a field

38307*412*11*
38703*412*11*A*
38703*412*11*AA*

I would like to remove the first * and replace the rest of the * with . and have no * at the end - how can I achieve this?

The result must be

38307/412.11
38703/412.11.A
38703/412.11.AA

Thanks Guys

Greg




 
Old July 11th, 2007, 01:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Is that the length of the first segement(5 chars) gonna be same for all the rows?

_________________________
- Vijay G
Strive for Perfection
 
Old July 11th, 2007, 03:42 AM
Authorized User
 
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Vijay

Yes the first segment will be 5 (char) in length for all rows

 
Old July 11th, 2007, 05:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try this. Anyways string manipulation is slow in sql.
Code:
DECLARE @var VARCHAR(100)
SET @var = '38703*412*11*AA*'
SELECT Left(Left(@var, 5) + '/' + Right(Replace(@var, '*', '.'), Len(@var) - 6 ), Len(@var) - 1)
Hope that helps.
Cheers.

_________________________
- Vijay G
Strive for Perfection
 
Old July 11th, 2007, 04:38 PM
Authorized User
 
Join Date: Jul 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank vijay

I would like to update my table not just select from it

Thanks
Greg

 
Old July 11th, 2007, 06:42 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

So, use the formula that Vijay provided in an UPDATE...

--Jeff Moden
 
Old July 12th, 2007, 01:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes Greg, then use the column name in place of @var in the UPDATE statement and you don't need the DECLARE and SET statements.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT replace for character entities atulshin XSLT 1 November 1st, 2008 05:19 AM
SQL REPLACE after a character. Stuart Stalker SQL Server 2000 6 April 11th, 2006 02:13 PM
Character replace function? echovue Access 2 December 21st, 2004 01:53 PM
Replace Character " fosca XSLT 1 November 11th, 2004 04:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.