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)
 Display results in single column

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2005-09-01 : 06:38:51
Hi,

I have a table
CREATE TABLE [Squares3_4_Details] (
[RowId] [int] IDENTITY (1, 1) NOT NULL ,
[mkid] [int] NOT NULL ,
[Techniques_4] [tinyint] NULL ,
[ProblemFeature_3] [tinyint] NULL ,
CONSTRAINT [PK_Squares3_4_Details] PRIMARY KEY CLUSTERED
(
[RowId]
) ON [PRIMARY]
) ON [PRIMARY]
GO


Sample Data:
mkid Techniques_4
52 12
52 11
52 9

If I do a select query such as select * from Squares3_4_Details where mkid=52 I get the following results:
mkid Techniques_4
52 12
52 11
52 9

However, the desired output should look like the following:
mkid Techniques_4
52 12119

Is there anyway of displaying Techniques_4 in one column?

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-01 : 06:41:24

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

eralper
Yak Posting Veteran

66 Posts

Posted - 2005-09-01 : 06:51:12
Hi,

DECLARE @str AS nvarchar(255)
SELECT
@str = COALESCE(@str + ',', '') + Cast(Techniques_4 as varchar(10))
FROM Squares3_4_Details WHERE mkid = 52
SELECT @str


You can have a look at the article http://www.kodyaz.com/article.aspx?ArticleID=29 for COALESCE function samples.

Eralper
http://www.kodyaz.com



-------------
Eralper
http://www.kodyaz.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-01 : 07:05:59
It should be noted that this will work only for one mkid
For multiple ids, you need to use Function as specified by me
And you can also use ISNULL

Madhivanan

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

- Advertisement -