Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help with insert into query plz

Author  Topic 

ndn_24_7
Starting Member

23 Posts

Posted - 2005-01-18 : 16:53:01
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 combine the narr field in table2 with Narrative in table1. 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

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-18 : 16:57:32
It would be best to post an example with data. Show us what the two tables data look like, then show us the expected result set using that data.

Tara
Go to Top of Page

ndn_24_7
Starting Member

23 Posts

Posted - 2005-01-18 : 17:26:46
the data in Table2 looks like this
ID nincident ncompl nfilename narr
7512 86 CUSTOMER GARRETT MORRIS 113-01-05 <Long Text>
7514 Casino Property Damage 112-01-05 <Long Text>
7515 Intoxication Security 116-01-05 <Long Text>
7516 Lost Properity Security 118-01-05 <Long Text>

The data in Table1 is kind of long, I scaled it down to the important ones.

ID FileName Narative

7512 113-01-05 [Want to put narr from table2 here]
7514 112-01-05
7516 118-01-05


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-18 : 17:30:36
SELECT t1.[ID], t1.FileName, t2.narr
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.[ID] = t2.[ID]

Tara
Go to Top of Page

ndn_24_7
Starting Member

23 Posts

Posted - 2005-01-18 : 19:51:43
It worked!!!!!!!!!!!!
Thank you for all you assistance, I greatly appreciate it
Go to Top of Page
   

- Advertisement -