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

Help with insert into query plz

Hello all,

I'm trying combine 2 tables data into a single table. My tables look
like this

Table1
ID int 4
filename nvarchar 25
incident nvarchar 50
dreport nvarchar 10
treport nvarchar 7
doccur nvarchar 10
DateOccured datetime 8
toccur nvarchar 7
loc nvarchar 55
ucode nvarchar 20
rwby nvarchar 30
disp nvarchar 55
Narrative ntext 16

Table2
ID int 4
nincident nvarchar 50
ncompl nvarchar 50
nfilename nvarchar 25
narr ntext 16

I used these 2 statements to narrow each table down to matching
filenames:

Select *
INTO TABLE1b
from table1
where exists(select * from table2 where
table1.filename = table2.nfilename)

SELECT *
INTO TABLE2b
FROM table2
WHERE exists(select * from table1 where
table1.filename = table2.nfilename)

My issue now is how to copy the narr field in table2 and insert it in
the Narrative field in table1 where table1.filename = table2.nfilename.
For every matching filename and nfilename(both are the keys) I need to
pull the narr field from table2 and insert it into Narrative in
table1. Does this make sense? Any assistance is greatly appreciated

Jul 23 '05 #1
5 3204
begin tran

update table1
set narrative=ltrim(rtrim(narrative)) + ltrim(rtrim(narr))
from table1 A
join table2 B
on A.filename=B.nfilename

select top 500 * from table1

-- if it looks correct then run the following line
--- COMMIT
-- if looks wrong then run this line
--- ROLLBACK

Jul 23 '05 #2
On 18 Jan 2005 13:26:05 -0800, ndn_24_7 wrote:

(snip)
ssue now is how to copy the narr field in table2 and insert it in
the Narrative field in table1 where table1.filename = table2.nfilename.
For every matching filename and nfilename(both are the keys) I need to
pull the narr field from table2 and insert it into Narrative in
table1. Does this make sense? Any assistance is greatly appreciated


Hi ndn_24_7,

Something like this, maybe?

UPDATE Table1
SET Narrative = (SELECT Table2.Narr
FROM Table2
WHERE Table2.nfilename = Table1.filename)
WHERE EXISTS (SELECT *
FROM Table2
WHERE Table2.nfilename = Table1.filename)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3
I got this error when running Hugo query
[The text, ntext, and image data types are invalid in this subquery or
aggregate expression.]

and this error when running louis query
[Argument data type ntext is invalid for argument 1 of rtrim function.]
any sugestions

Jul 23 '05 #4
On 18 Jan 2005 14:30:56 -0800, ndn_24_7 wrote:
I got this error when running Hugo query
[The text, ntext, and image data types are invalid in this subquery or
aggregate expression.]

and this error when running louis query
[Argument data type ntext is invalid for argument 1 of rtrim function.]
any sugestions


Hi ndn_24_7,

Try this variation on Louis' query:

update table1
set narrative=narr
from table1 A
join table2 B
on A.filename=B.nfilename
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #5
YES!!!!!!!!!!!!!!!!!!!!!!!!!
it worked, Thank you all for your help. I greatly appreciate it

Jul 23 '05 #6

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

Similar topics

2
by: Philip Hachey | last post by:
I think this is do-able, and possibly even simple, but it's been too many years since I've done anything significant with SQL. Any help would be appreciated. I have two tables, PAY and CHG. ...
1
by: Jimmy Tran | last post by:
Hi All, I have a table below and I want to design a query to pull all the members from the TABLE into a Query Result and into a single column with points assigned appropriately, but I am having...
2
by: Preston Landers | last post by:
Hello all. I am trying to write a query that "just" switches some data around so it is shown in a slightly different format. I am already able to do what I want in Oracle 8i, but I am having...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
2
by: KoliPoki | last post by:
Greetings. I'm having a little trouble with a query. The idea is simple I need to display a list of recently unique visited URLs and the last time I visited. I have 2 table one stores the...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
1
by: sujithegr8 | last post by:
HIii... Its me sujith i've done something with AJAX. but for the rest i need someo ones help.. i've done half the work. there are two tables. "ajax1" and "ajax2" (check db.sql)
4
by: Tonio Tanzi | last post by:
I have the following problem in a Win 2000 Server + SQL Server 2000 environment and I hope somewhat can help me to resolve it (after many days of useless attempts I am desperate). In my database...
2
by: Dinesh | last post by:
Hi experts, I am working on SQL Server 2005. Now i have to write a query which will extract some information from a table. My main table is having few columns supose 3 columns. EmpID ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.