Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Advanced Query

Author  Topic 

GoodFella3993
Starting Member

8 Posts

Posted - 2010-10-06 : 09:13:32
I have the following Table


1 | 2001,2002,2003 | ABC
2 | 2003,2004,2005 | DEF
3 | 1999,2000,2001 | HIG

I need to break up the 3rd column so that there is only one year for each row which will in tern create additional rows. It should look like this:

1 | 2001 | ABC
1 | 2002 | ABC
1 | 2003 | ABC
2 | 2003 | DEF
2 | 2004 | DEF
2 | 2005 | DEF
3 | 1999 | HIG
3 | 2000 | HIG
3 | 2001 | HIG

Any idea? The year column may one different amount of years in the original data set.

Shilpa22
Starting Member

37 Posts

Posted - 2010-10-06 : 09:21:32
Split the Year Column(CSV). You will have to write a user defined function for that and insert the values in the table.

Thanks in Advance
Shilpa
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-06 : 09:28:32
Hi,

Have a look at :
http://www.sommarskog.se/arrays-in-sql-2005.html


Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page
   

- Advertisement -