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
 SQL Server Development (2000)
 Concatenation of rows in Function

Author  Topic 

scelamko
Constraint Violating Yak Guru

309 Posts

Posted - 2007-11-15 : 15:43:08
I have table - employeedescription which stores description of the employee. An employee can have multiple descriptions, below functions returns all the employeedescription for each employee, Is ther any way to concatenate all the descriptions for an employee into a single row

empid empdescription
_______________________________
1 Joined in 1971
1 Raise in 1976
1 change department in 1980

output should be

empid empdescription
_______________________________
1 Joined in 1971 Raise in 1976 change department in 1980


ALTER function [dbo].[F_GETDESC](@sk bigint) returns varchar(2000)
as
begin
declare @desc varchar(2000)

SELECT @desc= ltrim(rtrim(description))+ '...'
FROM employeedescription
WHERE employeedescription.key=@sk

return @desc

end

Any suggestions and input should help

Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-15 : 15:49:18
SELECT @desc = isnull(@desc, '') + ltrim(rtrim(description)) + ','
FROM employeedescription
WHERE employeedescription.key = @sk
ORDER BY description


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -