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)
 filter based update

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2013-02-07 : 06:51:56
Hi

I need to filter based on this query result...


SELECT dbo.tbl_OrderInfo.IsFetched
FROM dbo.tbl_Customer INNER JOIN
dbo.tbl_Login ON dbo.tbl_Customer.CustID = dbo.tbl_Login.CustID INNER JOIN
dbo.tbl_OrderInfo ON dbo.tbl_Login.UID = dbo.tbl_OrderInfo.UserUniqueID
WHERE (dbo.tbl_Customer.CustID = 89) AND (dbo.tbl_OrderInfo.IsFetched = 0) OR
(dbo.tbl_OrderInfo.IsFetched IS NULL)




I need to update all dbo.tbl_OrderInfo.IsFetched and set them to dbo.tbl_OrderInfo.IsFetched = 1, how do change the code above?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-07 : 06:59:14
[code]
UPDATE dbo.tbl_OrderInfo
SET dbo.tbl_OrderInfo.IsFetched = 1
FROM dbo.tbl_Customer INNER JOIN
dbo.tbl_Login ON dbo.tbl_Customer.CustID = dbo.tbl_Login.CustID INNER JOIN
dbo.tbl_OrderInfo ON dbo.tbl_Login.UID = dbo.tbl_OrderInfo.UserUniqueID
WHERE (dbo.tbl_Customer.CustID = 89) AND (dbo.tbl_OrderInfo.IsFetched = 0) OR
(dbo.tbl_OrderInfo.IsFetched IS NULL)
[/code]

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

Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-07 : 07:01:05
"I need to update all dbo.tbl_OrderInfo.IsFetched" <-- You mean all that are returned via the select query? If so:
--SELECT dbo.tbl_OrderInfo.IsFetched
UPDATE dbo.tbl_OrderInfo SET
IsFetched = 1
FROM dbo.tbl_Customer
INNER JOIN dbo.tbl_Login
ON dbo.tbl_Customer.CustID = dbo.tbl_Login.CustID
INNER JOIN dbo.tbl_OrderInfo
ON dbo.tbl_Login.UID = dbo.tbl_OrderInfo.UserUniqueID
WHERE (dbo.tbl_Customer.CustID = 89)
AND (dbo.tbl_OrderInfo.IsFetched = 0)
OR (dbo.tbl_OrderInfo.IsFetched IS NULL)
Go to Top of Page
   

- Advertisement -