-- SQL 2000, Retrieve desired data
-- With SQL 2000, we will create a User Defined Function to do the concatenation.
-- While this solution can also be used with SQL Server 2005/SQL Server 2008,
-- the previous suggestion is more efficient.
CREATE FUNCTION dbo.fnMakeCommaDelimitedList
( @TempID int )
RETURNS varchar(1000)
AS
BEGIN
DECLARE @TempTable table
( TempValue varchar(20) )
DECLARE @TempList varchar(1000)
SET @TempList = ''
INSERT INTO @TempTable
SELECT DocumentId
FROM TechnicalDocSubscriberDoc
WHERE SubscriberId = @TempID
IF @@ROWCOUNT > 0
UPDATE @TempTable
SET @TempList = ( @TempList + TempValue + ', ' )
RETURN substring( @TempList, 1, ( len( @TempList ) - 1 ))
END
-- Usage
SELECT
ID, contactname, companyname, email, email, companyadd, suburb, state, postcode, contactphoneno,
SubscriberList = dbo.fnMakeCommaDelimitedList( ID )
FROM technicaldocsubscriber
GROUP BY ID, contactname, companyname, email, email, companyadd, suburb, state, postcode, contactphoneno
-- Clean up
DROP FUNCTION dbo.fnMakeCommaDelimitedList