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)
 Comma separated list

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-10-10 : 07:41:48
Rakhi writes "I am running SQL 7 and had a question about a SELECT statement I'm struggling with:

DECLARE @CList varchar(1000)
select
o.orderdate, o.id,o.billtoname, o.grandtotal,
(
SELECT @Clist = (COALESCE(@CList + ', ', '') + CAST(ProductID AS nvarchar(5)))
from vworderdetails where orderid = o.id
)as ProductList
from vworders o
join vwcourseorders oc
on o.id = oc.id
where o.orderdate>='10/03/05'
and o.orderdate<='10/07/05'
order by o.orderdate desc

Here is the results I'm trying to retrieve:
ORDERID, ORDERDATE, BILLTONAME, GRANDTOTAL, PRODUCTLIST
---------------------------------------------------------
1234, 10/04/05, John Doe, 1000.00, 681,682,683,684
1235, 10/05/05, Jane Doe, 1500.00, 684,685,686,687,688
..and so on...

When I run the query above, I get an error at the stmt:
SELECT @Clist = (COALESCE(@CList + ', ', '') + CAST(ProductID
The error msg reads:
Incorrect syntax near '='"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-10 : 07:42:53
Refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -