Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I 'sum' character strings in a simple way ?
Message
De
07/05/2003 11:44:39
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00785310
Message ID:
00785854
Vues:
10
You're welcome, I'm glad it helped...

>Thanks John! It was helpfull.
>
>>Hi Jozef,
>>
>>There is no set based way to do this with one TSQL statement. Without knowing your application here is something to consider; it could be accomplished in TSQL with something like the following using a temporary table. So for what it is worth...
>>
>>
>>CREATE TABLE #tbl_temp (field1 int,field2 varchar(8000))
>>DECLARE @field1 int
>>DECLARE @field2 char(6)
>>DECLARE temp_cursor CURSOR LOCAL FOR SELECT field1,field2 FROM dbo.mydata ORDER BY field1
>>OPEN temp_cursor
>>
>>FETCH NEXT FROM temp_cursor INTO @field1,@field2
>>WHILE @@FETCH_STATUS = 0
>>BEGIN
>>	IF EXISTS(SELECT field1 FROM #tbl_temp WHERE field1 = @field1)
>>		UPDATE #tbl_temp SET field2 = field2 + @field2
>>			WHERE field1 = @field1
>>	ELSE
>>		INSERT INTO #tbl_temp (field1,field2) VALUES (@field1,@field2)
>>	
>>	FETCH NEXT FROM temp_Cursor INTO @field1,@field2
>>END
>>
>>SELECT field1,field2 FROM #tbl_temp
>>DEALLOCATE temp_cursor
>>DROP TABLE #tbl_temp
>>
>>
>>John
>>
>>>I have a table like this (on SQLServer) ?
>>>
>>>field1 (int) field2 (char)
>>>1 aaa
>>>1 bbbb
>>>2 ccccc
>>>2 bb
>>>2 dd
>>>2 hh
>>>
>>>How to get such results using T-SQL statment ?
>>>
>>>field1 'sum' of field2
>>>1 aaa bbbb
>>>2 ccccc bb dd hh
>>>
>>>
>>>Thanks in advance
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform