473,795 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple rows combined into onerow and onecolumn separated by a special character

Hi All :
CREATE TABLE TABLEA(Person Varchar(20), Country Varchar(20), Subject
Varchar(20), Type Char(1))

INSERT INTO TABLEA VALUES ('Einstein', 'Germany', 'Physics', 'P')
INSERT INTO TABLEA VALUES ('Kant', 'Germany', 'Philosophy', 'Q')
INSERT INTO TABLEA VALUES ('Kafka', 'Germany', 'Writer' , 'W')

INSERT INTO TABLEA VALUES ('Aristotle', 'Greece', 'Philosophy', 'Q')
INSERT INTO TABLEA VALUES ('Archimedes', 'Greece', 'Physics', 'P')
INSERT INTO TABLEA VALUES ('Homer', 'Greece', 'Writer' , 'W')

SELECT * FROM TABLEA

I am on SQL 2000.
I need an output where i have to have a resultset grouped on Type, but
the results in one row.

In the resultset I need

TypeP Person Type P Country, Type Q Person, Type Q Country, Type
W Person Type W Country
---------------------------------------------------------------------------------------------------------------------
Einstein:Archim edes Germany:Greece Kant:Aristotle Germany:Greece
Kafka:Homer Germany:Greece
*************** *************** *************** *************** ***
I have written a puesdo-cursor code to do the same, but if there is a
way to do as a set operation, that would be great

Please select as a whole and past in query analyser as the resultset
is all overlaid when i paste in this box.
Thank you
RS

Oct 19 '07 #1
2 1816
Hi David :

Thank you much.
This gives me 2 values, min and max.
but, I will have a total of 4 persons on philosophy and it could be
either 0 or 1 or 2 or 3 or 4 persons in philisophy.
Is it possible to do a set operation for that ?

What i came up with is 4 sql set stmts.
first one is insert stmt of a random philisopher in temp table:

second will be update stmt and in where clause excluding what is
already in temp table
third stmt is another update to 3rd column excluding the two already
in temp table
and fourth stmt

Is there a better way ?
Thank you

Oct 24 '07 #2
(th*********@gm ail.com) writes:
Thank you much.
This gives me 2 values, min and max.
but, I will have a total of 4 persons on philosophy and it could be
either 0 or 1 or 2 or 3 or 4 persons in philisophy.
Is it possible to do a set operation for that ?
It could certainly help if you could produce a more extensive set of
sample data, also explain the logic to get the desired result.

But if I am guessing correctly what you are trying to achieve, the
answer is that on SQL 2000, your prospects are bleak, at as long as
there is no upper limit of how many persons there can be.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Oct 24 '07 #3

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

Similar topics

5
1699
by: Manu | last post by:
Hi, Here's what i want to accomplish. I want to make a list of frequenctly occuring words in a group of files along with the no of occurances of each The brute force method will be to read the file as a string,split,load the words into a dict with words as key and no of occurances as key. Load the next file ,iterate through the new words increment the value if there is
3
10775
by: Shuaib | last post by:
Is there any way for Oracle (using standard SQL rather than PL/SQL) to suppress the newline character when returning a list of rows. For example, if I have a table EMP with several records. When I issue the statement: SELECT name FROM emp I would like to get a single row output back comprising the following:
5
3718
by: dnsstaiger | last post by:
I try to accomplish the following: I have two tables which are connected via a third table (N:N relationship): Table 1 "Locations" LocationID (Primary Key) Table 2 "Specialists" SpecialistID (Primary Key)
10
22928
by: Robert Stearns | last post by:
In a table which has an animal id, its dam id and sire id, I want to see a combined list of all animal ids. I tried the following, which did not work, but did not give any error messages: select regnum from ( select regnum from nullid.angus_in union select sire_regnum as regnum from nullid.angus_in union select dam_regnum as regnum from nullid.angus_in ) as t group by t.regnum having count( * ) > 1;
1
3362
by: poohnie08 | last post by:
i have a excel spreadsheet showing staff name, date,work hour, ot hour, slot1, slot2, slot3, slot4 and others). The "()" will keep repeating from day 1 until end of month. eg in excel spreadsheet, ============================================================================== A1 |A2 A3 A4 A5 A6 A7 A8 |A9 A10 A11 | 01/02/04 |02/02/04 StaffName |Work Hr OT Hr Slot1...
7
43142
by: Mintyman | last post by:
Hi, I'm working on a system migration and I need to combine data from multiple rows (with the same ID) into one comma separated string. This is how the data is at the moment: Company_ID Material 0x00C00000000053B86 Lead 0x00C00000000053B86 Sulphur 0x00C00000000053B86 Concrete
0
7499
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i can make report from my database on the one sheet rather than querying each select statement ( I will use MS Query from the Excel) ========================================================= 1) select convert(varchar, create_date_time, 112) as Date,...
1
3386
by: assgar | last post by:
Hi I was using a schroll bar to display multiple rows of dynamically created from database records. The scrolling was not displaying the data properly so I have decided to use pagination. The problem I am having is, if I select one item on page #1 and another on page #5 only the last item selected on page #5 is stored in the array. How can I store selections from multiple pages into one array?
4
1844
by: gentsquash | last post by:
On some of my course pages, I quote (with attribution) small sections of Wikipedia and the like. E.g, the top of http://en.wiktionary.org/wiki/entropy has "entropia" in Greek font, http://en.wikipedia.org/wiki/Goedel has the o-umlaut from German, and
3
4266
by: Andrew Meador | last post by:
I have searched and found where this has been discussed, but the suggestions I have found have all ended up tuning into debated about whether it needs to be done - but - as far as I can tell - I need to. I am trying to setup a database that tracks parcel history. I want to be able to choose a parcel and see a list of its children (smaller pieces to the property that have been sold off) and a list of its parents (previous tracts/parcels...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.