ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Update Primary Table and records having dependencies in SQL Server<p>Hi <a class="username" rel="nagaraju60"> nagaraju60</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">CREATE PROCEDURE CheckAndIpdate @ItemId INT, @OrderId INT AS BEGIN DECLARE @Id INT SELECT @Id = FK_order_Id FROM Tbl_Itms WHERE Item_Id = @ItemId AND FK_order_Id = @OrderId UPDATE Tbl_Itms SET Item_Status = &#39;C&#39; WHERE Item_Id = @ItemId AND FK_order_Id = @OrderId UPDATE Tbl_Ordrs SET Order_Status = &#39;C&#39; WHERE Order_Id = @Id END</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/415658/Update-Primary-Table-and-records-having-dependencies-in-SQL-Server/https://www.aspforums.net:443/Threads/415658/Update-Primary-Table-and-records-having-dependencies-in-SQL-Server/Thu, 20 Jun 2019 06:21:36 GMTUpdate Primary Table and records having dependencies in SQL Server<p>Dear @pandeyism,</p> <p>Thanks for your valuable reply. I am getting my output by using below Stored Procedure.</p> <pre class="brush: sql">CREATE PROCEDURE CheckAndIpdate @ItemId INT, @OrderId INT AS BEGIN Declare @Item_Stat_Cnt int Declare @Item_Cnt int UPDATE Tbl_Itms SET Item_Status=&#39;C&#39; WHERE Item_Id=@ItemId AND FK_order_Id=@OrderId SET @Item_Cnt=(SELECT Count(*) as Itm_Cnt FROM Tbl_Itms WHERE Item_Id=@ItemId AND FK_order_Id=@OrderId) SET @Item_Stat_Cnt=(SELECT Count(*) as Item_Stat_Cnt FROM Tbl_Itms WHERE FK_order_Id=@OrderId AND Item_Status=&#39;C&#39;) IF(@Item_Cnt=@Item_Stat_Cnt) BEGIN UPDATE Tbl_Ordrs SET Order_Status=&#39;C&#39; WHERE Order_Id = @OrderId END END </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/415658/Update-Primary-Table-and-records-having-dependencies-in-SQL-Server/https://www.aspforums.net:443/Threads/415658/Update-Primary-Table-and-records-having-dependencies-in-SQL-Server/Mon, 24 Jun 2019 05:16:27 GMT