I need to take any amount of rows and turn them into one single row. I'm exporting some data from sql. The program its going into only has one note field. I've used UNION and those types of functions, not sure what to do this time. This is SQL server and will be part of a stored procedure.
example data:
NOTES NOTE TIME
yayayay hey yo 4/25/2006
blah blah blaaah 5/1/2006
second note blah 5/2/2006
Into One column, One row
NOTE
4/25/2006: yayayay hey yo 5/2/2006: blah blah blaaah 5/2/2006: second note blah
4 46599
you'll have to do it by query with the fields joined as one with "+" signs -
INSERT INTO YourTable (yourColumn) SELECT Column1 + Column2 + ColumnEtc AS OnePieceOfData FROM TheOtherTable
-
you'll have to do it by query with the fields joined as one with "+" signs -
INSERT INTO YourTable (yourColumn) SELECT Column1 + Column2 + ColumnEtc AS OnePieceOfData FROM TheOtherTable
-
I'm a little further along, and what you've said isn't what I'm looking for.
Basically I need to take every note one of our users may or may not have left and combine that and some other fields into one giant text field so it can be exported to a new program the lawyers are using.
So I thought I could cursor through the notes combing as I go and came up with this: -
CREATE PROCEDURE prcCombineInquiryNotes (@inquiry_id int,
-
@massive_note varchar(8000) OUTPUT
-
)
-
AS
-
-
--these hold what's in the select statement each go around
-
DECLARE @username varchar(50)
-
DECLARE @notes varchar(500)
-
DECLARE @noteDate datetime
-
-
-
DECLARE curInqNotes CURSOR FOR
-
-
SELECT inquiry_notes.notes, CONVERT(VARCHAR, inquiry_notes.note_date_time, 101) AS noteDate, administrator.username
-
FROM inquiry_notes INNER JOIN
-
administrator ON inquiry_notes.admin_id = administrator.member_id
-
WHERE (inquiry_notes.inquiry_id = @inquiry_id)
-
-
-- open cursor
-
OPEN curInqNotes
-
-
-- Perform the first fetch.
-
FETCH NEXT FROM curInqNotes INTO @notes, @noteDate, @username
-
-
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
-
WHILE @@FETCH_STATUS = 0
-
BEGIN
-
-- Combines multiple notes into one note
-
-
select @massive_note = 'Note: ' + @notes + CHAR(10)
-
select @massive_note = @massive_note + 'Left by: ' + @username + ' On: ' + CONVERT(VARCHAR, @noteDate, 101) + CHAR(10)
-
-
-- This is executed as long as the previous fetch succeeds.
-
FETCH NEXT FROM curInqNotes INTO @notes, @noteDate, @username
-
END
-
-
CLOSE curInqNotes
-
DEALLOCATE curInqNotes
-
-
RETURN
-
GO
-
The problem is I can't figure out how to combine the above procedure with the notes combined, with the other procedure that will be pulling the main data. -
SELECT IC.last_name, IC.first_name, IC.first_name + ' ' + IC.last_name AS full_name, IC.street, IC.suite, IC.postal_code, IC.city, IC.state_code,
-
IC.email_address, IC.home_phone, RTRIM(CONVERT(CHAR, I.inquiry_date, 101)) AS OpenDate, LKIT.inquiry_type AS ReferredBy,
-
'Inquiry ID#: ' + CONVERT(VARCHAR, I.inquiry_id) + ' Subject: ' + I.inquiry_subject + CONVERT(VARCHAR(3000), I.inquiry) AS Notes, 'NC' AS Class,
-
'LK' AS Attorney
-
-
FROM dbo.inquiry I INNER JOIN
-
dbo.inquiry_contact IC ON I.inquiry_contact_id = IC.inquiry_contact_id INNER JOIN
-
dbo.lk_inquiry_type LKIT ON I.inquiry_type_id = LKIT.inquiry_type_id
-
WHERE (I.division_id = 5) AND (I.inquiry_status_id = 3)
-
See I need the notes from prcCombineInquiryNotes by each record in the above query to go into the Notes column in the above query. I thought maybe I could do two cursors one inside the other but that didn't work out.
Anyone have any ideas?
Basically I need to take every note one of our users may or may not have left and combine that and some other fields into one giant text field so it can be exported to a new program the lawyers are using.
Ok, I understand that now, since your exporting for another program, would (assuming MS SQL Server) the BCP Export feature do what you want to do?
I'm a little further along, and what you've said isn't what I'm looking for.
Basically I need to take every note one of our users may or may not have left and combine that and some other fields into one giant text field so it can be exported to a new program the lawyers are using.
So I thought I could cursor through the notes combing as I go and came up with this: -
CREATE PROCEDURE prcCombineInquiryNotes (@inquiry_id int,
-
@massive_note varchar(8000) OUTPUT
-
)
-
AS
-
-
--these hold what's in the select statement each go around
-
DECLARE @username varchar(50)
-
DECLARE @notes varchar(500)
-
DECLARE @noteDate datetime
-
-
-
DECLARE curInqNotes CURSOR FOR
-
-
SELECT inquiry_notes.notes, CONVERT(VARCHAR, inquiry_notes.note_date_time, 101) AS noteDate, administrator.username
-
FROM inquiry_notes INNER JOIN
-
administrator ON inquiry_notes.admin_id = administrator.member_id
-
WHERE (inquiry_notes.inquiry_id = @inquiry_id)
-
-
-- open cursor
-
OPEN curInqNotes
-
-
-- Perform the first fetch.
-
FETCH NEXT FROM curInqNotes INTO @notes, @noteDate, @username
-
-
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
-
WHILE @@FETCH_STATUS = 0
-
BEGIN
-
-- Combines multiple notes into one note
-
-
select @massive_note = 'Note: ' + @notes + CHAR(10)
-
select @massive_note = @massive_note + 'Left by: ' + @username + ' On: ' + CONVERT(VARCHAR, @noteDate, 101) + CHAR(10)
-
-
-- This is executed as long as the previous fetch succeeds.
-
FETCH NEXT FROM curInqNotes INTO @notes, @noteDate, @username
-
END
-
-
CLOSE curInqNotes
-
DEALLOCATE curInqNotes
-
-
RETURN
-
GO
-
The problem is I can't figure out how to combine the above procedure with the notes combined, with the other procedure that will be pulling the main data. -
SELECT IC.last_name, IC.first_name, IC.first_name + ' ' + IC.last_name AS full_name, IC.street, IC.suite, IC.postal_code, IC.city, IC.state_code,
-
IC.email_address, IC.home_phone, RTRIM(CONVERT(CHAR, I.inquiry_date, 101)) AS OpenDate, LKIT.inquiry_type AS ReferredBy,
-
'Inquiry ID#: ' + CONVERT(VARCHAR, I.inquiry_id) + ' Subject: ' + I.inquiry_subject + CONVERT(VARCHAR(3000), I.inquiry) AS Notes, 'NC' AS Class,
-
'LK' AS Attorney
-
-
FROM dbo.inquiry I INNER JOIN
-
dbo.inquiry_contact IC ON I.inquiry_contact_id = IC.inquiry_contact_id INNER JOIN
-
dbo.lk_inquiry_type LKIT ON I.inquiry_type_id = LKIT.inquiry_type_id
-
WHERE (I.division_id = 5) AND (I.inquiry_status_id = 3)
-
See I need the notes from prcCombineInquiryNotes by each record in the above query to go into the Notes column in the above query. I thought maybe I could do two cursors one inside the other but that didn't work out.
Anyone have any ideas?
http://vj-blogsql.blogspot.com/
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Valerie |
last post by:
Hi everyone,
I really appreciate if anyone could help me with this tricky problem
that I'm having. I'm looking for a sample script to combine data in
multiple rows into one row. I'm using...
|
by: Antanas |
last post by:
Is it possible to combine multiple rows returned from select statement
into one row?
SELECT NAME FROM TABLE1;
I want all names to be combined into one row seperated by commas.
|
by: musicloverlch |
last post by:
I have a table with multiple records in it. I am being forced to
combine multiple records into one record in order to be uploaded to a
website, and I only get one record per client. How can I...
|
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 ...
|
by: Apple001 |
last post by:
Hi all!
I am having trouble with joining multiple rows into one row. I will appreciate any help.
For columns in the query, I have: invID(autot number), entryDate, invDate, vendor, invoiceAmount...
|
by: Mike Reid |
last post by:
I have designed a Database that will import data and assign values for ordering material. However I am having problems as I currently have to drop this data into an Excel sheet and apply a Pivot...
|
by: kagweh |
last post by:
Am new to Access so go easy
Each serial number has several comments made for it and what I need is to combine all comments for each serial into one row separated by a comma or l.
Now here are...
|
by: klbachrodt |
last post by:
Hi all - I've been browsing this forum for a while now, looking for help, and finally decided to join and ask my question, since I'm not terribly good at writing SQL queries in Access. Here is my...
|
by: aas4mis |
last post by:
I have a table with a deviceid, attribute type, and attribute value. There are many attributes for a single device id. I want my query to retrieve a single device id with multiple attribute values....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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,...
| |