Question: I'm trying to split a column in my table into two using SQL and I can't figure it out. Here is an example of a

I'm trying to split a column in my table into two using SQL and I can't figure it out. Here is an example of a row:

Movie ID | MovieTitle | Genre

1 , Toy Story (1997) , Animated

I want to split my movie titlle field into a separate row called "Year". Which obviously displays the years. I have tried using this SQL (among others) and it keeps giving me errors:

select case when CHARINDEX('(',MovieTitle)>0 then SUBSTRING(MovieTitle,1,CHARINDEX('(',MovieTitle)-1) else name end MovieTitle, CASE WHEN CHARINDEX('(',MovieTitle)>0 THEN SUBSTRING(MovieTitle,CHARINDEX('(',MovieTitle)+1,len(MovieTitle)) ELSE NULL END as Year from Movies

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!