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)
 conditional update

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-03-26 : 04:52:42
Hi

I have 2 tables, "order" and "orderrows"

table "orderrows" look like this...

OrderName (nvarchar 50)
ArticleID (int)
Qty (int)
IsFetched (bit)


table "order" look like this...
OrderName (nvarchar 50)
Adress (nvarchar)
IsFetched (bit)


I would like to create a stored procedure that pass the OrderName as parameter and then check if all "IsFetched" = 1 in the "orderrow" table, if so update "IsFetched" to 1 in table "order" based on OrderName parameter.


Can someone show me how to do this?



stepson
Aged Yak Warrior

545 Posts

Posted - 2014-03-26 : 05:09:45
[code]

CREATE PROCEDURE usp_Update_OrderName

@OrderName as varchar(100)

AS
BEGIN
IF NOT Exists(select * from OrderRows where OrderName =@orderName and IsFetched=0)
BEGIN
UPDATE ORDER
SET isFetched=1
WHERE OrderName=@OrderName and IsFetched=0

END
END

[/code]


sabinWeb MCP
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-03-26 : 05:13:53
Thank you very much!
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-03-26 : 05:23:33
Your welcome!


sabinWeb MCP
Go to Top of Page
   

- Advertisement -