Select * from [GLAccGLCaption] where [GLCaptionPlanId] = 0

Select * from [GLAccGLCaption] where [GLCaptionPlanId] = 0

Select Top 20 [DBId] from [GLAccGLCaption] where [GLCaptionPlanId] = 0 Group by [DBId] Order by [DBId]

Select [GLAccGLCaption].[DBId] as [ResDBId]
, [GLAccGLCaption].[GLCaptionId] as [ResGLCaptionId]
, [GLAccGLCaption].[DGLCaptionId] as [ResDGLCaptionId]
, [GLAccGLCaption].[CGLCaptionId] as [ResCGLCaptionId]
, [GLAccGLCaption].[GLCaptionPlanId] as [ResGLCaptionPlanId]
, [GLCaption].[GLCaptionPlanId] as [ResNewGLCaptionPlanId]
from [GLAccGLCaption] INNER JOIN [GLCaption]
ON ([GLAccGLCaption].[GLCaptionId] = [GLCaption].[Id] and [GLAccGLCaption].[DBId] = [GLCaption].[DBId])
where Not [GLAccGLCaption].[GLCaptionPlanId] = [GLCaption].[GLCaptionPlanId]

 

Update [GLAccGLCaption] Set [GLAccGLCaption].[GLCaptionPlanId] = [ResGLAccGLCaption].[ResNewGLCaptionPlanId] from
(
Select [GLAccGLCaption].[DBId] as [ResDBId]
, [GLAccGLCaption].[GLCaptionId] as [ResGLCaptionId]
, [GLAccGLCaption].[DGLCaptionId] as [ResDGLCaptionId]
, [GLAccGLCaption].[CGLCaptionId] as [ResCGLCaptionId]
, [GLAccGLCaption].[GLCaptionPlanId] as [ResGLCaptionPlanId]
, [GLCaption].[GLCaptionPlanId] as [ResNewGLCaptionPlanId]
from [GLAccGLCaption] INNER JOIN [GLCaption]
ON ([GLAccGLCaption].[GLCaptionId] = [GLCaption].[Id] and [GLAccGLCaption].[DBId] = [GLCaption].[DBId])
where Not [GLAccGLCaption].[GLCaptionPlanId] = [GLCaption].[GLCaptionPlanId]
)
as [ResGLAccGLCaption] INNER JOIN [GLAccGLCaption]
ON ([ResGLAccGLCaption].[ResDBId] = [GLAccGLCaption].[DBId]
and [ResGLAccGLCaption].[ResGLCaptionId] = [GLAccGLCaption].[GLCaptionId]
and [ResGLAccGLCaption].[ResDGLCaptionId] = [GLAccGLCaption].[DGLCaptionId]
and [ResGLAccGLCaption].[ResCGLCaptionId] = [GLAccGLCaption].[CGLCaptionId])
where Not [ResGLAccGLCaption].[ResNewGLCaptionPlanId] = [GLAccGLCaption].[GLCaptionPlanId]