Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to do sum of Varchar

Author  Topic 

ramana_cr
Starting Member

14 Posts

Posted - 2002-01-22 : 11:28:39
Hi,
Can you please help me with this problem

table
col1 col2
1 'AB'
1 'CD'

How can i get the record
1, 'AB, CD' ( Something like select col1, sum(col2) from table group by col1-- if col2 was number)

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-22 : 11:44:01
look at the article on creating csv strings.

declare @s varchar(1000)
select @s = coalesce(@s + ',','') + b
from tbl
where a = 1

select 1, @s



==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.

Edited by - nr on 01/22/2002 11:45:39
Go to Top of Page

ramana_cr
Starting Member

14 Posts

Posted - 2002-01-22 : 11:49:13
nr,
Thanks... Is there anyway we can do it With a Select statement. I am trying to create a view...

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-01-22 : 12:24:04
Read this and the links inside it:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=12149

They're about the best you can do; I don't believe you can do this in a view though, because it will require multiple passes to consolidate the rows into one.

Go to Top of Page
   

- Advertisement -