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.
| 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 Table1ID 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 TABLE1bfrom table1where exists(select * from table2 wheretable1.filename = table2.nfilename)SELECT * INTO TABLE2bFROM table2WHERE exists(select * from table1 wheretable1.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 |
 |
|
|
ndn_24_7
Starting Member
23 Posts |
Posted - 2005-01-18 : 17:26:46
|
| the data in Table2 looks like thisID nincident ncompl nfilename narr7512 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 Narative7512 113-01-05 [Want to put narr from table2 here]7514 112-01-05 7516 118-01-05 |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-01-18 : 17:30:36
|
| SELECT t1.[ID], t1.FileName, t2.narrFROM Table1 t1INNER JOIN Table2 t2ON t1.[ID] = t2.[ID]Tara |
 |
|
|
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 |
 |
|
|
|
|
|