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)
 Trying to parse a field into multiple fields

Author  Topic 

alanrwest
Starting Member

1 Post

Posted - 2006-08-08 : 19:25:52
OK, I'm not quite sure how to go about this. Basically I have a field in a table and I want to extract part of the field's value and insert it into another field. Let me give an example:

I have a field FullID which contains strings like "UST\ADAM56G". I want to strip the "UST\" portion (everything before and including the "\") and insert the substring "ADAM56G" into another field in the same row called PartialID.

So basically, I'm trying to insert into a row a string based on a substring of another field in the same row.

Here's what I've tried so far (obviously to no luck):
UPDATE Employees
SET Partial ID =
SELECT SUBSTRING(FullID, CHARINDEX('\', FullID) + 1,
{ fn LENGTH(FullID) } - CHARINDEX('\', FullID) + 1)

Any thoughts on how I can accomplish this? Thanks so much in advance for the help!!

Alan

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-08-08 : 19:31:58
UPDATE Employees
SET PartialID = SUBSTRING(FullID, CHARINDEX('\', FullID) + 1, DATALENGTH(FullID))

Tara Kizer
Go to Top of Page
   

- Advertisement -