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)
 some help with splitting

Author  Topic 

lbodie
Starting Member

4 Posts

Posted - 2003-05-08 : 11:53:23
I think I found what I need but don't understand the logic when I need to add another element. Can someone help with the following code:

UPDATE myTable SET Fname=SubString(Name, 1, CharIndex('*', Name)-1),
MName=SubString(Name, CharIndex('*', Name)+1, CharIndex('*', Name, CharIndex('*', Name)+1) - CharIndex('*', Name)-1),
Lname=SubString(Name, CharIndex('*', Name, CharIndex('*', Name)+1)+1, DataLength(Name))

This uses 3 elements of the array field and mine has four. can someone supply the missing piece?



jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-05-08 : 13:53:30
Ask your question in the original thread in which that solution was given to you, and people will know what you're talking about ...

- Jeff
Go to Top of Page

shifis
Posting Yak Master

157 Posts

Posted - 2003-05-08 : 23:01:15
I tried this and it funtion, I hope it help you.
DECLARE @Name AS CHAR(100)
DECLARE @Fname AS CHAR(100)
DECLARE @Mname AS CHAR(100)
DECLARE @Lname AS CHAR(100)
DECLARE @Pname AS CHAR(100)

SET @Name='UNO*DOS*TRES*CUATRO'

SET @Fname=SubString(@Name, 1, CharIndex('*', @Name)-1)
SET @Mname=SubString(@Name, CharIndex('*', @Name)+1, CharIndex('*', @Name, CharIndex('*', @Name)+1) - CharIndex('*', @Name)-1)
SET @Lname=SubString(@Name, CharIndex('*', @Name, CharIndex('*', @Name)+1)+1,CharIndex('*', @Name,CharIndex('*', @Name, CharIndex('*', @Name)+1)+1)-CharIndex('*', @Name, CharIndex('*', @Name)+1)-1 )
SET @Pname=SubString(@Name,CharIndex('*', @Name,CharIndex('*', @Name, CharIndex('*', @Name)+1)+1)+1 , DataLength(@Name))

SELECT @Fname
SELECT @Mname
SELECT @Lname
SELECT @Pname




Edited by - shifis on 05/08/2003 23:01:52
Go to Top of Page
   

- Advertisement -