472,358 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

SQL Statement Help

Hello,

Thanks for taking the time to help me out with this. I've been pulling
my hair out trying to figure this out.

SERVER: Microsoft SQL Server 2000

TABLE STRUCTURE:
terms_no varchar 10
note_no int 4
note_text varchar 60

SAMPLE DATA:
terms_no | note_no | note_text
2 | 1 | This is a test.
2 | 2 | This is a test second line.
3 | 1 | Another test.

THE ISSUE:
There can be multiple note_text(s) for each term_no, which can be
sorted by the note_no. I would like to take each and combine them into
one string. There can be an unlimited amount of note_no(s) and
term_no(s).

DESIRED RESULT:
If the terms_no is 2 then combine the two lines into one string like
the following:

note_text_combined
This is a test. This is a test second line.

Any ideas on how I can accomplish this through SQL I would very much
appreciate it. If I had the choice to redesign this table I would
without question, however, it can't be done.

Thanks again ! I really appreciate it !

cwwilly

Jul 23 '05 #1
1 917
(cw*****@gmail.com) writes:
Thanks for taking the time to help me out with this. I've been pulling
my hair out trying to figure this out.

SERVER: Microsoft SQL Server 2000

TABLE STRUCTURE:
terms_no varchar 10
note_no int 4
note_text varchar 60

SAMPLE DATA:
terms_no | note_no | note_text
2 | 1 | This is a test.
2 | 2 | This is a test second line.
3 | 1 | Another test.

THE ISSUE:
There can be multiple note_text(s) for each term_no, which can be
sorted by the note_no. I would like to take each and combine them into
one string. There can be an unlimited amount of note_no(s) and
term_no(s).

DESIRED RESULT:
If the terms_no is 2 then combine the two lines into one string like
the following:

note_text_combined
This is a test. This is a test second line.

Any ideas on how I can accomplish this through SQL I would very much
appreciate it. If I had the choice to redesign this table I would
without question, however, it can't be done.


In SQL 2000, you need to do this with an iterative solution, although
for some speed, you could accumulate all note_no = 1 at once.

It's not clear where you will save the result, but you use a varchar(8000) -
and hope that you don't run out of space.

If the result for one termns_no can exceed 8000 characters, you need to
do this client-side.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

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

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

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
2
by: Little PussyCat | last post by:
Hello, I hope you can help me. We have a SQL Server 2000 database at work, (which works with a VB6 frontend) which grew to a considerable size, so one of my past colleagues sent me this...
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
10
by: John Smith | last post by:
Can you do a Select Statement within a Select Statement? I want to build a query similar to queries built in Access which link to other queries but using only SQL Statements. Is it possible? If...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
4
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.