SELECT eventname ,CASE WHEN charindex('vs', eventname) > 0 THEN rtrim(SUBSTRING(eventname, charindex('vs', eventname) + 3, len(eventname))) END Away_Team ,replace(replace(eventname, CASE WHEN charindex('vs', eventname) > 0 THEN rtrim(SUBSTRING(eventname, charindex('vs', eventname), len(eventname))) END, ''), SUBSTRING(replace(eventname, CASE WHEN charindex('vs', eventname) > 0 THEN rtrim(SUBSTRING(eventname, charindex('vs', eventname), len(eventname))) END, ''), 0, PatIndex('%[0-9]%', replace(eventname, CASE WHEN charindex('vs', eventname) > 0 THEN rtrim(SUBSTRING(eventname, charindex('vs', eventname), len(eventname))) END, '')) + 2), '') Home_Team --SUBSTRING(replace(eventname,case when charindex('vs',eventname)>0 then --rtrim(SUBSTRING(eventname,charindex('vs',eventname),len(eventname))) end,''),0,PatIndex('%[0-9]%', --replace(eventname,case when charindex('vs',eventname)>0 then --rtrim(SUBSTRING(eventname,charindex('vs',eventname),len(eventname))) end,''))+2) FROM tablename
where eventname is a column name
No comments:
Post a Comment