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 2000 Forums
 Transact-SQL (2000)
 Concatenating multiple rows to a single column

Author  Topic 

timgaunt
Posting Yak Master

115 Posts

Posted - 2004-11-11 : 11:25:51
Hi,

I expect this is simple and I'm just using the wrong terminology but basically what I would like to do is build a new column which contains the user's roles from the rows return from an "Access Levels" table:

UsersTable:
============
field name data type length
------------ ----------- --------
U_ID int 4
U_UName char 255
U_UPass char 255

AccessLevels:
============
field name data type length
------------ ----------- --------
AG_ID int 4
AG_Name nvarchar 255

AccessLevelsMatrix:
============
field name data type length
------------ ----------- --------
AG_ID int 4
U_ID int 4

Once the users record has been validated on the server I would simply like to return the Username and the users roles (ie can_edit, can_delete etc). In the past I have done this on the web server but now rather than having a couple of trips to the SQL Server I would like to streamline things a little.

Origionally I was thinking of something like:

UPDATE #TempTable
SELECT [User_Roles] & [AG_Name] As [User_Roles], [U_Name] FROM #TempTable WHERE [U_Name] = @UName

But I can't figure out the "for each row in" type statement. Any ideas?

Cheers.

Tim

timgaunt
Posting Yak Master

115 Posts

Posted - 2004-11-11 : 12:26:06
Since posting I've worked out that I should have been searching on concatenate which has thrown a whole new element into the SP, so is there anyway I can concatenate multiple rows into a single column?
Go to Top of Page

timgaunt
Posting Yak Master

115 Posts

Posted - 2004-11-11 : 12:30:48
Think I've found a solution thanks :)
Go to Top of Page
   

- Advertisement -