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 |
ganny
Yak Posting Veteran
51 Posts |
Posted - 2008-12-29 : 06:50:18
|
Hi,I have a table as below:Report_Name ---- Report_Audience==============================================XYZreport ---- Finance,Admin,Management,ABCreport ---- Finance,Management,But, I want to show the above table as below:Report_Name ---- Report_Audience==============================================XYZreport ---- FinanceXYZreport ---- AdminXYZreport ---- ManagementABCreport ---- FinanceABCreport ---- ManagementKindly advise me how to write a sql query to get the result like this. Thanks in advance. |
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2008-12-29 : 07:36:27
|
Hi Try ThisSELECT s.report_name,SUBSTRING(s.report_audience, v.Number - 1,COALESCE(NULLIF(CHARINDEX(',', s.report_audience, v.Number), 0), LEN(s.report_audience) + 1) - v.Number + 1) AS valueFROM reports AS sINNER JOIN master..spt_values AS v ON v.Type = 'p'WHERE SUBSTRING(',_' + s.report_audience, v.Number, 1) = ','Jai Krishna |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|