473,395 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

spread query

Hi,
I have a table as follows:

HostId PurposeId
====== =========
1 3
1 5
1 6
2 1
2 3
I'm looking for a query which will return:

HostId Purposes
====== ========
1 3, 5, 6
2 1, 3

Is it possible?

Thanks in advance.
Jul 20 '05 #1
2 1689
oj
Yaron,

You could try this...

--sql2k+
create function dbo.udf(@h int)
returns varchar(8000)
as
begin
declare @s varchar(8000)
select @s=isnull(@s+',','')+cast(PurposeId as varchar)
from tb
where HostId=@h
return @s
end
go

select HostId, dbo.udf(HostId) as Purposes
from (select distinct HostId
from tb)Derived

Also, we have a solution that would extend more functionalities. Here is one of
the functionalities http://rac4sql.net/onlinehelp.asp?topic=236 that related to
your current issue.

--
-oj
http://www.rac4sql.net
"Yaron Avior" <ya****@mercury.co.il> wrote in message
news:1b**************************@posting.google.c om...
Hi,
I have a table as follows:

HostId PurposeId
====== =========
1 3
1 5
1 6
2 1
2 3
I'm looking for a query which will return:

HostId Purposes
====== ========
1 3, 5, 6
2 1, 3

Is it possible?

Thanks in advance.

Jul 20 '05 #2
oj (no**********@home.com) writes:
Yaron,

You could try this...

--sql2k+
create function dbo.udf(@h int)
returns varchar(8000)
as
begin
declare @s varchar(8000)
select @s=isnull(@s+',','')+cast(PurposeId as varchar)
from tb
where HostId=@h
return @s
end
go


But beware that this relies on behaviour that is not defined. You
may get what you expect, but there is no guarantee. See
http://support.microsoft.com/default.aspx?scid=287515.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gary Herron | last post by:
Hi list, Can someone who has built the SpreadModule on a windows machine please send me the results of the build (or just point me an a binary distribution). Here's why: I'm starting to...
3
by: jim2372 | last post by:
Hello, I work for a very small trading firm. We are thinking of developing our own trading application to automatically make spread trades on the e-cbot platform. We are somewhat unsatisfied...
0
by: WStoreyII | last post by:
Hello, I was wondering if there was a way to open a spread sheet up in a windows mdi form. I have tried the spreadsheet control but that does not work because i wish to open up an exisiting...
2
by: RICHARD BROMBERG | last post by:
I wrote a small Access application that accepts a City Name and a Street Name and runs a Query based on them . I want to create an Excel Spread sheet that contains all the matches found by the...
5
by: stuart79 | last post by:
I am looking for a code that enables me to open another excel spread sheet while i am in my XL form i have this code - Workbooks.Open Filename:= "OtherFilename.xls" - which opens up the XL spread...
2
by: glibo | last post by:
I am trying to change the tab name when i open a excell spread sheet on the run time in c#. I changed it in the code: Response.AddHeader("content-disposition","filename=" + sFileName + ".xls");...
1
by: Alia Khan | last post by:
Hi I am creating a dts in which I want to write my query results in a spread sheet I am using this syntax select Super_REgion, sum(num_of_offers) Contracts, sum(num_of_acnts) Accounts from...
1
by: abraham.pinsker | last post by:
Hi, I'm having the following problem. I have a table that contains information about books people read, i.e. each row has two columns, people id and book id. I need to do the following query:...
0
by: codewarrior1241 | last post by:
Hi all, I will try to be as clear as possible with my application, maybe ppl familiar with asyncore can help me out :-) Basically, I have python 2.5 in SuSe running with a server written using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.