Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I 'sum' character strings in a simple way ?
Message
From
06/05/2003 16:08:44
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00785310
Message ID:
00785571
Views:
15
This message has been marked as the solution to the initial question of the thread.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform