Question : CHARINDEX Syntax

Hello Experts,

I need some help with the syntax of the following:
INSERT INTO tblUserTeams (TeamName, LeaderCode, LeaderDiscipline, MemberCode, MemberDiscipline)
VALUES ('TEAM_C','SQU01', 'PT',
LEFT('WIL01-JACK WILLS, PTA',(CHARINDEX('-','WIL01-JACK WILLS, PTA') - 1)),
RIGHT('WIL01-JACK WILLS, PTA',(CHARINDEX(',','WIL01-JACK WILLS, PTA') - 1)))

What I want is everything to the left of the '-' (WIL01 in the example) to go intro MemberCode and everything to the right of the ',' (PTA in the example) to go into MemberDiscipline.

Thanks in advance for your help,

JackW9653

Answer : CHARINDEX Syntax

Ah sorry, misread your query; you want this:

INSERT INTO tblUserTeams (TeamName, LeaderCode, LeaderDiscipline, MemberCode, MemberDiscipline)
VALUES ('TEAM_C','SQU01', 'PT',
LEFT('WIL01-JACK WILLS, PTA',(CHARINDEX('-','WIL01-JACK WILLS, PTA') - 1)),
SUBSTRING('WIL01-JACK WILLS, PTA',CHARINDEX(',','WIL01-JACK WILLS, PTA')+1,LEN('WIL01-JACK WILLS, PTA')-CHARINDEX(',','WIL01-JACK WILLS, PTA')))
Random Solutions  
 
programming4us programming4us