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
 Was going to delete, now need to update

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-21 : 13:15:11
So i was originally going to look for matches between two tables by using:
SELECT * FROM GCSOCONV.dbo.MNICOMPARE t1
INNER JOIN MNI.dbo.MNI t2
ON FNAME = FNAME
AND MNAME = MNAME
AND LNAME = LNAME
AND t1.DOB = t2.DOB
AND t1.RACE = t2.RACE
AND t1.HAIR = t2.HAIR
ORDER BY t1.LNAME

Then delete those entries by changing the select statement to a delete statement. I've decided against deleting those entries and instead have added a bit column with a default value of "true" to the MNICOMPARE table. Now i would like this query to change the value of that column ('INCLUDE') to '0' where there is a match. I know this is an update/set statement, but how do i work it syntactically into the select? Would it be?:
Update MNICOMPARE set INCLUDE='0' where SELECT(SELECT * FROM GCSOCONV.dbo.MNICOMPARE t1
INNER JOIN MNI.dbo.MNI t2
ON FNAME = FNAME
AND MNAME = MNAME
AND LNAME = LNAME
AND t1.DOB = t2.DOB
AND t1.RACE = t2.RACE
AND t1.HAIR = t2.HAIR)
ORDER BY t1.LNAME

Or am i wrong?

thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-02-21 : 13:20:35
UPDATE t1
SET INCLUDE = '0'
FROM GCSOCONV.dbo.MNICOMPARE t1
INNER JOIN MNI.dbo.MNI t2
ON FNAME = FNAME
AND MNAME = MNAME
AND LNAME = LNAME
AND t1.DOB = t2.DOB
AND t1.RACE = t2.RACE
AND t1.HAIR = t2.HAIR

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-21 : 13:22:42
Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-02-21 : 13:25:01
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -