473,387 Members | 1,790 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,387 software developers and data experts.

combining rows into a single row output

Hi,
for the purpose of this question i have 2 tables:

Table1 with fields ID, Name, NoteID
Table2 with fields NoteID, Note_Text

for every 1 record in Table1 there are many in Table2. If i use a standard JOIN i get multiple rows in a recordset but what i want is 1 Row with the field "Notes" that would comtain all the Note_text entries for the record in Table1.

example:
ID, Name, Notes
------------------------
1, Bob, Test note1, Test note2, Test note3
2, Carl, <null>
3, paul, note for paul

can anyone help please?
Apr 20 '07 #1
1 2554
-- Try this:

SET NOCOUNT ON

DECLARE @ID varchar (50)
DECLARE @Name varchar (200)
DECLARE @StringText varchar(8000)


Declare curBuildString cursor
static for
select distinct id, Name from Table1

OPEN curBuildString
FETCH NEXT FROM curBuildString
INTO @ID, @Name

WHILE @@FETCH_STATUS = 0
BEGIN
SET @StringText = @id + ', ' + rtrim(@name) +', '
SELECT Table2.notetext into #t1
FROM Table1
INNER JOIN Table2 ON Table1.noteid = Table2.noteid
WHERE Table1.ID = @ID

WHILE (Select top 1 notetext from #t1) is not null
BEGIN
select @StringText = @StringText + rtrim((select top 1* from #t1)) +', '
DELETE FROM #t1 WHERE #t1.notetext = (SELECT TOP 1 notetext FROM #t1)
END

print left(@StringText, len(@StringText) -1)
DROP TABLE #t1
FETCH NEXT FROM curBuildString
INTO @ID, @Name
END

CLOSE curBuildString
DEALLOCATE curBuildString
SET NOCOUNT OFF
GO
Apr 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: mikea_59 | last post by:
I am having trouble combining similar elements. Elements can be combined if they have the same name and the same attribute values. I can handle single level elements but am having problems with...
2
by: Chris Mullins | last post by:
I've spent a bit of time over the last year trying to implement RFC 3454 (Preparation of Internationalized Strings, aka 'StringPrep'). This RFC is also a dependency for RFC 3491...
6
by: yoohanman | last post by:
Hi, I have a select statment that correctly returns zero rows at times. I would like to be able to return the value 0 (a single row with the value 0) whenever the logic returns zero rows. ...
4
by: mike | last post by:
I have a database table like the following: id|name|item_id|sequence and the following instance data: 1|Apple|419841|1 2|Orange|419841|2 3|Banana|935890|1 4|Lime|959081|1
5
by: rAinDeEr | last post by:
Consider the following table (Single level of hierarchy ... No need for recursion) PRIMARY_COLUMN SECONDARY_COLUMN ----------------------------- ----------------------------------- ...
1
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured...
2
by: rpeacock | last post by:
I have a function that takes a field with values separated by commas within the field and splits them to multiple rows. Example: Field - Interior Value - abc,def,efg,ghi Output: ID Item 1 ...
5
by: Tristan Miller | last post by:
Greetings. Is it possible using HTML and CSS to represent a combining diacritical mark in a different style from the letter it modifies? For example, say I want to render Å‘ (Latin small letter...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
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
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
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...

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.