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
 Transact-SQL (2000)
 A Tough Select

Author  Topic 

mayoorsubbu
Yak Posting Veteran

95 Posts

Posted - 2008-10-31 : 20:51:50
Hi Folks,

I have a table like so :-

Itemcode Derscription Location
______________________________________
1234 Chocolate Bay1
1234 Chocolate Bay2

How do I produce a result using the conventional select statement as follows :-

Itemcode Description Location
______________________________________
1234 Chocolate Bay1, Bay2

As of now I am using a Cursor and acheiving the output

Thanx

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-01 : 02:35:31
make a function like below
CREATE FUNCTION dbo.concat_values 
( @item INT,@Description VARCHAR(1000) )
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @p VARCHAR(8000) ;
SET @p = '' ;
SELECT @p = @p + Location + ','
FROM YourTable
WHERE Itemcode = @item
AND Description=@Description
RETURN @p
END

And, as for its usage:

SELECT Itemcode,Description,dbo.concat_values(Itemcode,Description ) AS Location
FROM YourTable
GROUP BY Itemcode,Derscription
Go to Top of Page

mayoorsubbu
Yak Posting Veteran

95 Posts

Posted - 2008-11-02 : 11:51:26
Visakh,

Thanx a lot

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-02 : 11:53:11
Welcome
Go to Top of Page
   

- Advertisement -