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
 General SQL Server Forums
 New to SQL Server Programming
 Validate two table and insert results in a new one

Author  Topic 

AlexandreSilva
Starting Member

2 Posts

Posted - 2012-05-23 : 07:31:45
Hello, i am a beginner in sql Server and i need to do a job but i don't know how to do it.

i have two table (table1 and table2) and i have to validate if a spcific column from table1 exists on table2 and insert the result to a new table that is composed with fileds from table1 and table2.

i done this...

INSERT INTO table3
SELECT Imagem, Periocidade FROM table1 A
WHERE A.Imagem in
(select REPLACE (clientName,'_DB2','')
from table2)

but it don't work

Can anyone please help

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-05-23 : 07:42:53
Does table3 already exist? If not, try
SELECT Imagem, Periocidade
INTO table3
FROM table1 A
WHERE A.Imagem in
(select REPLACE (clientName,'_DB2','')
from table2)


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

AlexandreSilva
Starting Member

2 Posts

Posted - 2012-05-23 : 09:20:31
Thank you Jim For your answer, but i need to put in table 3 columns from table2 also.

For exemple:

Table 1 have fields like:
-Imagem
-Tipo_Backup
-Periocidade

Table2 have fields like:
-ClientName
-Outcome
-StartDateTime
-EndDateTime

Table3 need to be composed by
-Imagem (from table1)
-Tipo_Backup (from Table1)
-Periocidade (from Table1)
-Outcome (from Table2)
-StartDatetime (from Table2)
-EndDatetime (from Table2)

Thanks in advance,

Alex
Go to Top of Page
   

- Advertisement -