473,395 Members | 1,537 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.

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:Archimedes 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 1799
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*********@gmail.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****@sommarskog.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
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...
3
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...
5
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"...
10
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...
1
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,...
7
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 ...
0
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...
1
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...
4
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, ...
3
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
0
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,...
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.