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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-02-25 : 07:38:35
|
| writes "Hi,I've a query that retrieves the data like...I'm retrieving the details of all the users who belong to more than one detartment.UserId DEPT1 201 232 202 215 215 23Now what I need is to display the same data like,UserID DEPT1 DEPT21 20 232 20 215 21 23without using any temp tables / cursors.And at the moment my query is,SELECT DISTINCT a.userid, a.deptcodeFROM users a JOIN users b ON a.userid = b.userid AND a.deptcode <> b.deptcodeGROUP BY a.userid , a.deptcodeORDER BY a.userid SQL server 2000 version 8.0 on Windows 2K pro" |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2004-02-25 : 09:42:30
|
Let's see I want recursion, but I can't use any features in SQL to accomplish it. OK. The only thing I can think of here is using some sort of delimited list creator. You can do a search here for "Converting Multiple Rows into a CSV String (Set Based Method)" but it will give you rows with a comma-delimited list, not separate fields.UserID Departments------ -----------1 20,232 20,215 21,23 You can then pull that out into your report and separate them in the presentation layer. |
 |
|
|
|
|
|