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 2005 Forums
 Transact-SQL (2005)
 best way to u to query this

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-07-06 : 11:42:24
insert into [a](name,adress,city)

select name,address,city from a2 where moveto=1

how can i further restrcit this to only insert into a from a2 if the record doesn't exist in a (not looking at the autonumber id field but looking at name,address,city fields to see if all exist and are the same

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-06 : 12:01:53
insert into [a](name,adress,city)
select name,address,city
from a2
where moveto=1
and not exists(select * from [a] as dest where dest.name=a2.name and dest.address=a2.address and dest.city=a2.city)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-07-07 : 03:54:27
my problem is the 2 tables have a different collation by default and i don't want to change the table as I don't know what it will affect.

where would i add the collate SQL_Latin1_General_CP1_CI_AS
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-07 : 04:05:29
Add it on the side where another collation is used in the table.
For example if table a2 has another collation:
where
dest.name=a2.name collate SQL_Latin1_General_CP1_CI_AS and
dest.address=a2.address collate SQL_Latin1_General_CP1_CI_AS and
dest.city=a2.city collate SQL_Latin1_General_CP1_CI_AS


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -