/*
   دوشنبه, 12 فروردین 1403 - 17:56:45 ب.ظ
   User: 
   Server: TAHERIAN
   Database: ATNDB
   Application: 
*/

Use ATNDBTest
Go
/*=============================================================================================================*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.FactorHeader ADD
	BasedDoc bit NULL
GO
ALTER TABLE dbo.FactorHeader SET (LOCK_ESCALATION = TABLE)
GO
Update 
	FactorHeader
Set
	BasedDoc = 1
Where
	Serial In(
				Select 
					FactorHeaderRef 
				From 
					FactorDetail Inner Join
					FactorDetailAndItselfBridge On FactorDetail.Serial = FactorDetailAndItselfBridge.MasterFactorDetailRef
			)
COMMIT