473,804 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.nfilenam e)

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

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.nfilenam e.
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 3228
begin tran

update table1
set narrative=ltrim (rtrim(narrativ e)) + ltrim(rtrim(nar r))
from table1 A
join table2 B
on A.filename=B.nf ilename

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.nfilenam e.
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.nfilenam e = Table1.filename )
WHERE EXISTS (SELECT *
FROM Table2
WHERE Table2.nfilenam e = 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.nf ilename
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
1660
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. PAY contains payments to employees and the dates each payment was made. CHG contains dates employees were hired and to what group they belonged. CHG also contains any changes (updates) to which group they belong along with the effective date of...
1
1251
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 a lot of difficulties doing this. Any help is greatly appreciated. TABLE MEMBER1 MEMBER2 POINTS Joe Don 2 Macy 1
2
2256
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 trouble making it work in SQL Server 2000. I am not a database newbie, but I can't seem to figure this one out so I am turning to the newsgroup. I am thinking that some of the SQL Gurus out there have done this very thing a thousand times before...
28
3308
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 make-believe challenge in order to avoid confusing the issue further. Suppose I was hosting a dinner and I wanted to invite exactly 12 guests from my neighborhood. I'm really picky about that... I have 12 chairs besides my own, and I want them all...
2
4450
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 user and time/date and another has the URL. So all I need is the URL (no duplicates) and the last visit.
2
2917
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 avoid the problem by avoiding the table control or resorting to databound controls that better manage state for me. I hope to understand how to solve the problem by using the Table web control and sticking to the approach of building the table at run...
3
3454
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 the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
1
1657
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
14142
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 I have two table: - master(id, field1, field2, ...) - detail(id0, id, progr, data, sede, esecutori, brani_autori) in a master-detail relation with "id" as foreign key. The fields of the "detail" table are:
2
1918
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 Supervisor_ID Date_Of_Visit Now records are entering in this tabl. Date of visit is date of
0
9716
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10354
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.