SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Validate two table and insert results in a new one
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AlexandreSilva
Starting Member

2 Posts

Posted - 05/23/2012 :  07:31:45  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2868 Posts

Posted - 05/23/2012 :  07:42:53  Show Profile  Reply with Quote
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 - 05/23/2012 :  09:20:31  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000