second line was supposed to be value2
Main Topics
Browse All TopicsHi,
Since a while I'm messing arround trying to build a "Split Function" in SQL Server:
declare @value nvarchar(50)
declare @splitter nvarchar(50)
declare @delimit nvarchar(1)
select
@delimit = '/'
select
@splitter = 'Any Section/Department A'
SET
@value = SUBSTRING(@splitter,1,CHAR
select
@value as retSplittedValue
Looks good, but I'm only able to receive the string before the delimit: "Any Section"
I wonder if anyone has an idea how to get the the string behind the delimit: "Department A"
Best regards,
Raisor
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
sorry....also missed an @:
declare @value1 nvarchar(50)
declare @value2 nvarchar(50)
declare @splitter nvarchar(50)
declare @delimit nvarchar(1)
select
@delimit = '/'
select
@splitter = 'Any Section/Department A'
SET
@value1 = SUBSTRING(@splitter,1,CHAR
, @value2 = SUBSTRING(@splitter,CHARIN
select
@value1 as retSplittedValue1
, @value2 as retSplittedValue2
If you will only have 1 delimiter, you can use the technique discussed in the following link:
http://www.sql-server-help
Basically, it uses the PARSENAME function. To use it in your case:
DECLARE @splitter VARCHAR(50)
SET @splitter = 'Any Section/Department A'
SELECT PARSENAME(REPLACE(@splitte
Hi,
@jrb1: Thanks a lot jrb, I've tested your solution and it returned:
Server: Msg 170, Level 15, State 1, Line 10
Line 10: Incorrect syntax near ','.
@josenich: Your peace of code did the job!
Parameter set to "2" returns: 'Any Section'
Parameter set to "1" returns: 'Department A'
... and I'll read the article too!
Thanks for the quick and professional help!
Best regards,
Raisor
Business Accounts
Answer for Membership
by: jrb1Posted on 2005-10-14 at 13:30:44ID: 15088799
do it:
INDEX(@del imit,@spli tter)-1) DEX(@delim it,@splitt er)+1,LEN( splitter) - CHARINDEX(@delimit,@splitt er))
declare @value1 nvarchar(50)
declare @value1 nvarchar(50)
declare @splitter nvarchar(50)
declare @delimit nvarchar(1)
select
@delimit = '/'
select
@splitter = 'Any Section/Department A'
SET
@value1 = SUBSTRING(@splitter,1,CHAR
, @value2 = SUBSTRING(@splitter,CHARIN
select
@value1 as retSplittedValue1
, @value2 as retSplittedValue2