I am new to SQL Server (from MS Access)
I would like to concatenate a recordset into a single string such as:
FieldA
-------
101
210
206
Into 101,210,206
I have stored procedure started but it returns a null value:
------------------------------------
DECLARE @CurrentRow int
DECLARE @RowCount int,
@strResult varchar(8000)
-- Insert into temp table
DECLARE @temptable table(Id int primary key identity(1,1), HTEFund int)
INSERT INTO @temptable (HTEFund)
SELECT tblAccountMaster.GMFUND
FROM tblFundSummarySettingsA INNER JOIN tblAccountMaster ON
tblFundSummarySettingsA.GMFUND = tblAccountMaster.FSFund
GROUP BY tblFundSummarySettingsA.GMFUND, tblAccountMaster.GMFUND
SELECT @CurrentRow = 1
SELECT @RowCount=COUNT(Id) FROM @temptable
--For each record in @temptable do...
WHILE @CurrentRow <= @RowCount
BEGIN
SET @strResult = @strResult + (
SELECT HTEFund
FROM @temptable
WHERE id = @CurrentRow
SELECT @CurrentRow = @CurrentRow + 1
END
RETURN @strResult
Thanks for the help!
I would like to concatenate a recordset into a single string such as:
FieldA
-------
101
210
206
Into 101,210,206
I have stored procedure started but it returns a null value:
------------------------------------
DECLARE @CurrentRow int
DECLARE @RowCount int,
@strResult varchar(8000)
-- Insert into temp table
DECLARE @temptable table(Id int primary key identity(1,1), HTEFund int)
INSERT INTO @temptable (HTEFund)
SELECT tblAccountMaster.GMFUND
FROM tblFundSummarySettingsA INNER JOIN tblAccountMaster ON
tblFundSummarySettingsA.GMFUND = tblAccountMaster.FSFund
GROUP BY tblFundSummarySettingsA.GMFUND, tblAccountMaster.GMFUND
SELECT @CurrentRow = 1
SELECT @RowCount=COUNT(Id) FROM @temptable
--For each record in @temptable do...
WHILE @CurrentRow <= @RowCount
BEGIN
SET @strResult = @strResult + (
SELECT HTEFund
FROM @temptable
WHERE id = @CurrentRow
SELECT @CurrentRow = @CurrentRow + 1
END
RETURN @strResult
Thanks for the help!