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
 Need query for this

Author  Topic 

anup23
Starting Member

19 Posts

Posted - 2011-11-22 : 09:00:52
I have two tables A and B .. and in that combination of three columns are uniquie , I have to update a row of table as 0 if the combination these columns doesnt match ..
How can I write a query for this ...
Could you plz help

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-22 : 09:16:16
update tbl1
set ---
from tbl1 t1
left join tbl2 t2
on t1.col1 = t2.col1
and t1.col2 = t2.col2
and t1.col3 = t2.col3
where t2.is null


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

anup23
Starting Member

19 Posts

Posted - 2011-11-22 : 09:23:26
thanks for the reply.. what if i need to set the value 0 when those 3 columns are not equal.
Go to Top of Page

anup23
Starting Member

19 Posts

Posted - 2011-11-22 : 09:32:01
Just a doubt , y is this for???
where t2.is null
Go to Top of Page

anup23
Starting Member

19 Posts

Posted - 2011-11-22 : 09:43:32
I have two tables A and B .. and in that combination of three columns are uniquie , I have to update a column of table B as 0 if the combination these columns are not equal .
How can I write a query for this ...
Could you plz help

Sorry I guess earlier,I didnt explained my question clearly ...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-22 : 09:53:23
i had already given solution here

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=167732

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-22 : 10:04:38
quote:
Originally posted by anup23

I have two tables A and B .. and in that combination of three columns are uniquie , I have to update a column of table B as 0 if the combination these columns are not equal .
How can I write a query for this ...
Could you plz help

Sorry I guess earlier,I didnt explained my question clearly ...



That's what that statement does.
Gets all the rows fro tbl1 which don't have a row matching in tbl2 on the three columns. Just complete the set clause to set the value to 0.

The where clause is to restrict it to rows that don't match in the two tables.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -