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 46390
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
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...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
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.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
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...
|
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...
|
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....
| |