Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to derive the result set using SQL Statement
Message
 
 
À
05/07/2004 20:44:40
Rene Lovino
Bigfoot Global Solutions, Inc
Cebu, Philippines
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
00918903
Message ID:
00920889
Vues:
20
Hi Rene,

There's another way to get result w/o using cursor. I don't know if would work 'as is' in SQL Server 7 but I feel that it's worth sharing.
-- Drop temp. table if it existst
IF object_id('tempdb..#Temp01') IS NOT NULL
	DROP TABLE #Temp01

CREATE TABLE #Temp01 (
	pk int Identity, 
	Transfer char (10) NOT NULL,
	Item varchar (32) NOT NULL ,
	BinList varchar (1024)  NULL ) 


INSERT INTO #Temp01 (Transfer, Item )
  SELECT DISTINCT transfer, Item FROM mytable1

DECLARE @cnt int, @i int, @str varchar(1024)

SELECT  @cnt = MAX(pk) FROM #Temp01

SET @i = 0
WHILE @i < @cnt BEGIN
	SET @i = @i + 1
	SET @str = Null
	SELECT @str = ISNULL(@str + ', ', '') + bin
		FROM mytable1 mt
			JOIN #Temp01 tmp ON tmp.transfer = mt.transfer
				AND tmp.Item = mt.Item
				AND tmp.pk=@i
	UPDATE #Temp01 
		SET BinList = @str 
		WHERE pk = @i
END

SELECT * FROM #Temp01

-- Drop temp. table 
DROP TABLE #Temp01
>Thank you very much for your response. Your solution works properly in SQL Server 2000. However our application is selling accounting software to different users. Some of our users still using SQL Server 7 and UDF is not applicable in SQL Server 7. Our application want to maintain a code that can support both SQL Server 7 and SQL Server 2000.
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform