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
 SQL Server Development (2000)
 extracting first value from array

Author  Topic 

coultard1
Starting Member

4 Posts

Posted - 2005-01-06 : 20:42:41
I have a field which contains array information like this:

5;10;11.77;0;0;0;0;0;0


how do I just extract the first value (in the example 5) from the field? I have looked at the patindex and charindex, but my understanding is that they provide you with the index number if your extracting value is going to be constant? (i.e. always going to be 5?)

I have seen examples of substr used with charindex within it, but still can't get my head around it

Can anybody help?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-01-06 : 20:47:43
SELECT SubString(array, 1, CharIndex(';', array)-1) FROM myTable
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-07 : 01:37:36
Or you can extract any value via
http://www.mindsdoor.net/SQLTsql/f_GetEntryDelimiitted.html

select dbo.f_GetEntryDelimiitted (array, @n, ';', 'N')

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -