473,769 Members | 4,470 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Sql statement


--Table
Create table tableName (Field1 int, Field2 int)

Table Data
Field1 Field2
1 10
2 10
3 10
1 20
2 20
3 30

I need Like a Sql statement like

1 10 (any separator) 20
2 10 20
3 10 30
thx a lot waiting for result

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
1 1561
radha (po**********@y ahoo.co.in) writes:
--Table
Create table tableName (Field1 int, Field2 int)

Table Data
Field1 Field2
1 10
2 10
3 10
1 20
2 20
3 30

I need Like a Sql statement like

1 10 (any separator) 20
2 10 20
3 10 30
thx a lot waiting for result


It is not clear what result you are looking for. Do you want max or
min values? Or if there are 19 different values for Field1, do you want
all 19 values of Field2 in one row?

In the first case it's simple:

SELECT Field1, MIN(Field2), MAX(Field2)
FROM tableName
GROUP BY Field1

The recommendation for the second case is usually that you should to it
client-side, as SQL does not lend itself for this sort of thing. An
iterative solution is somewhat tedious to write, but it may be the best
way. I seem to recall that someone - I believe it was Anith Sen or
David Portas - a while back posted a set-based solution, which used an
auxilliary table with numbers from 1 to whatever number that is needed.
--
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 #2

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

Similar topics

5
3018
by: Alex | last post by:
I am having difficulty writing a SQL statement and I was wondering if one of you gurus could help me. I have a table that has three fields: InvoiceID, Item, ItemPrice. Each InvoiceID is associated with one or more Items. I am trying to write a SQL statement that returns the record (all three fields) for the least expensive item for each invoice (so the total number of records returned will be equal to the total number of unique Invoice IDs....
6
443
by: Pixie | last post by:
I was asked by professor to figure out the mistakes and fill in the functions for this program. I cannot figure it out and I hope someone can help me.Any input would be helpful. Thanks, PIXIE here is the program: // digits.cpp #include <iostream> using std::cout; using std::cin;
1
2154
by: Tom Rahav | last post by:
Hello all! I develop application in Visual Basic .NET and ORACLE database. My question is how do I "send" script file to the database using visual basic .net. Other words, is there any way to send to the database a script file to run, as done by: "@FullPath\FileName" in SQL PLUS ? If not, then I need your help with something else: I tried to send to the database the script file's content, in order to run the commands in it (create...
1
3182
by: JP | last post by:
I just installed db2 V8.1 and I am trying to create a simple compound statement in the command center script area and every time I would get the following error. what am i doing wrong? (note: my statement termination character is set to ";") i.e. of compound statement: begin atomic declare v_test SMALLINT; set v_test = 1;
7
2185
by: Buck Rogers | last post by:
Hi all! Newbie here. Below is an example from Teach Yourself C in 21 Days. My apologies if it is a bit long. What I don't understand is how the "get_data" function can call the "continue_function", and if NO is returned to "get_data", display_report executes and the program ends? Basically I am having trouble understanding the program flow within the "if" loop in the "main" function.
2
4722
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First question. I have a web survey that I am working on and have successfully dynamically taken the info from a database, displayed it on the screen and then taken the users answers and inserted them into a
2
1730
by: JRamirez | last post by:
Need help cannot figure out where I made the error. -------------------------------------------------------------------------------- Can someone view what I have, I need help I cannot figure out where I went wrong. Thanks /* Jose N. Ramirez CS151
14
1586
by: Pep | last post by:
I have a method in a class like this class myClass { ... ctros, dtor, etc ... string myClassMethod() { string myString = "";
6
2985
by: zaina | last post by:
hi everybody i am nwebie in this forum but i think it is useful for me and the member are helpful my project is about connecting client with the server to start exchanging messages between them. to be more clear we process this purpose we serve this to the student in the university. how?? student will send a message that contains his name,id and request by format the server want such as zaina-20024008-grade. the grade is the request...
2
8166
by: kya2 | last post by:
I am not able to create following store procedure. CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT ) RESULT SETS 1 LANGUAGE SQL BEGIN part1 DECLARE TOTAL_LEFT INT DEFAULT 0; SELECT COUNT(*)INTO TOTAL_LEFT FROM DBSAMBA.REPORTEDTRANSACTION_S; WHILE (TOTAL_LEFT > 0) DO
0
9425
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
10225
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
10053
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
10001
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,...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
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
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.