search char in String

Hi

Is there any function to seperate a sting (VARCHAR) into two based on a character in the string (e.g. '-').

In short is there "InStr" or "split" type function in T-SQL ? If not what is the alternative?

I have a column called "Range" (VarChar) in the table which has ranges like 1-14 or 15-49 etc.

I need to select records by compare a variable (numeric) against these ranges.

So for instace if the variable has 15 its in range 15-49.

I was thinking of spliting the range field into two so that comparison is possible.

Any suggestions?

thanks

[639 byte] By [Sam12] at [2007-12-21]
# 1

Hello,

does CHARINDEX suit your needs? For example, to return the starting position of the "*" character in string 'Hello * World' you would:

SELECT CHARINDEX('*', 'Hello * World')

This will return 7 (* beging the 7th character in the string). You can then use the LEFT and RIGHT functions to select either side of the "delimited" character:

Cheers

Rob

RobertVarga at 2007-9-10 > top of Msdn Tech,SQL Server,Transact-SQL...
# 2

that would be perfect. I will test it out.

Thanks

Sam12 at 2007-9-10 > top of Msdn Tech,SQL Server,Transact-SQL...
# 3
How would you select the next 3 characters? I cannot seem to use the MID fucnction.
BobKudulis at 2007-9-10 > top of Msdn Tech,SQL Server,Transact-SQL...
# 4
I got it but would like to see how you did it.
BobKudulis at 2007-9-10 > top of Msdn Tech,SQL Server,Transact-SQL...

SQL Server

Site Classified