>Cioè una stringa contenente tutti gli slave trovati dato un determinato
>codice master.
Evitando i cursori ti allego un esempio al volo:
CREATE TABLE #MasterSlave
(
IDMaster int
, IDSlave int
)
GO
INSERT INTO #MasterSlave (IDMaster, IDSlave)
VALUES (1,1)
INSERT INTO #MasterSlave (IDMaster, IDSlave)
VALUES (1,2)
INSERT INTO #MasterSlave (IDMaster, IDSlave)
VALUES (1,3)
INSERT INTO #MasterSlave (IDMaster, IDSlave)
VALUES (2,1)
INSERT INTO #MasterSlave (IDMaster, IDSlave)
VALUES (2,2)
INSERT INTO #MasterSlave (IDMaster, IDSlave)
VALUES (3,1)
GO
declare @stringa varchar(MAX)
select @stringa = COALESCE(@stringa, '') + CAST(IDSlave AS varchar(10)) + ','
from #MasterSlave
where IDMaster = 1
SET @stringa = LEFT(@stringa,LEN(@stringa)-1)
SELECT @stringa
DROP TABLE #MasterSlave
GO
Ciao!
--
Alessandro Alpi | SQL Server MVP
http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org