select 'PD'  as voucher_no ,getdate() as oper_date,a.item_no,isnull(abs(a.stock_qty),0) as real_qty,isnull(a.avg_cost,0) as price, isnull            (abs(a.stock_qty),0)*isnull(a.avg_cost,0) as sheet_amt,a.branch_no as branch_no,'' as d_branch_no,'PD' as trans_no,
           case when  a.stock_qty<0 then '-' else '+' end as db_no, b.main_supcust as supcust_no,'A' as sale_way,'1001' as oper_id
from #sdb..t_im_branch_stock a, #sdb..t_bd_item_info b where a.item_no=b.item_no and a.stock_qty <> 0 and a.branch_no = (select sys_var_value from #sdb.. t_sys_system where sys_var_id = 'g_stock_no')


