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
 Please help this newbie :)

Author  Topic 

aareth
Starting Member

2 Posts

Posted - 2007-06-27 : 08:14:43
Hello,

I have a database and in my database there are 5 different tables....

One of the tables is called "dvds" and another one is calles "reports"

What I want to do is, I would like to copy and paste everything in "reports" (column name: dvd) to "dvds" table (column name: name).

And I wan the SQL parameter to check everytime before it writes to "name" column in case that entry is already there. If the entry is already there then ignore and do not write, if it is not there then write it.

I am very sorry about my english and my knowledge on SQL.

Can anyone please help me to product this SQL command?

thank you so much.

Aareth

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2007-06-27 : 11:29:55
--insert into dvds (name)
select name from reports a
left join dvds b on a.name = b.name
where b.name is null

start out with the above...to see what SHOULD be inserted
and then remove the -- before the insert to action this change.
Go to Top of Page

aareth
Starting Member

2 Posts

Posted - 2007-06-29 : 11:12:16
I didnt understand this:(
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2007-06-29 : 12:04:51
run this bit 1st....to see what will be added....and to prove the SQL is syntactically correct and will do what you want it to do. once you are happy with this stage...proceed onto the next bit.

select name from reports a
left join dvds b on a.name = b.name
where b.name is null


then change the query to below (ie remove the 2 --)

insert into dvds (name)
select name from reports a
left join dvds b on a.name = b.name
where b.name is null
Go to Top of Page
   

- Advertisement -