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.
| Author |
Topic |
|
R1chard
Starting Member
2 Posts |
Posted - 2006-04-23 : 07:38:33
|
| Hi,I've got table with the data, unfortunately due to the database design theres a bunch of stuff in a single column but I need group but this column for an SQL View....Example:Person1 has a value of A,CPerson2 has a value of B,CI want to produce an SQL view (for reporting) that gives me:Group APerson 1Group BPerson2Group CPerson1Person2 So for each 'group' the person is repeated. So in view terms it'll be:group A, person1group B, person2group C, person1group C, person2Any thoughts? |
|
|
Kristen
Test
22859 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-04-24 : 05:47:19
|
Hi all,R1chard - I don't know if you've now got what you wanted, but here's one approach to your example...--datadeclare @t table (PersonId int, Groups varchar(100))insert @t select 1, 'A,C'union all select 2, 'B,C'--calculationdeclare @numbers table (i int identity(1, 1), x bit)insert @numbers select top 100 null from master.dbo.syscolumns a, master.dbo.syscolumns bselect left( substring(Groups, i, 100), charindex(',', substring(Groups, i, 100) + ',')-1) as [Group], PersonIdfrom @t inner join @numbers on substring(',' + Groups, i, 1) = ','Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|
|
|