Select * From dbo.BL_PaymentOrder Where ReceiverTax = '19001010457' And DateDeleted Is Null

Select * From dbo.BL_Persons Where PersonalID = '19001010457' And ID = '97441579-B38D-4787-B2CE-FC6BB3854DE2'

Select Distinct P.* 
From dbo.BL_ContractPersons CP
Join dbo.BL_AcceptanceActPaymentItems AI On AI.ContractPersonID = CP.ID
Join dbo.BL_Persons P On P.ID = CP.PersonID
Where CP.PersonID = '97441579-B38D-4787-B2CE-FC6BB3854DE2'



Declare @CurrentDate DateTime, @PersonIDOld Uniqueidentifier, @PersonIDNew Uniqueidentifier, @PersonalID nvarchar(50)
Set @CurrentDate = '2015-05-13 19:30:00.000'  --Select GetDate()
Set @PersonalID = '19001010457'
Set @PersonIDOld = '97441579-B38D-4787-B2CE-FC6BB3854DE2'
Set @PersonIDNew = '928C4EB4-642C-4D97-8B99-F355BEC30D69'  --Select NewId()

Begin Tran




Insert Into dbo.BL_Persons
        ( ID ,
          PersonalID ,
          FirstName ,
          LastName ,
          BirthDate ,
          Gender ,
          MobileIndexID ,
          Mobile ,
          Phone ,
          Email ,
          RegisteredAreaID ,
          RegisteredAddress ,
          ActualAreaID ,
          Address ,
          Status ,
          DateCreated ,
          DateChanged ,
          DateDeleted
        )
Select @PersonIDNew As ID ,
       PersonalID ,
       FirstName ,
       LastName ,
       BirthDate ,
       Gender ,
       MobileIndexID ,
       Mobile ,
       Phone ,
       Email ,
       RegisteredAreaID ,
       RegisteredAddress ,
       ActualAreaID ,
       Address ,
       Status ,
       DateCreated ,
       DateChanged ,
       DateDeleted 
From dbo.BL_Persons Where PersonalID = @PersonalID And ID = @PersonIDOld


Update P
Set P.DateDeleted = @CurrentDate
--Select * 
From dbo.BL_Persons P
Where PersonalID = @PersonalID And ID = @PersonIDNew


Update P
Set P.LastName = N'აბშილავა-ბუიუქქოი',
	P.DateCreated = @CurrentDate
--Select * 
From dbo.BL_Persons P
Where PersonalID = @PersonalID And ID = @PersonIDOld





Rollback
Commit
