IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_account_items]') AND type = 'V')
DROP VIEW [dbo].[mps_account_items]
GO


create view mps_account_items as
select top 10000 ai_id,ai_cmpid,aib_bcid ai_bcid,ai_code,ai_caption,ai_direction,ai_display,ai_full,ai_faiid,ai_ffaiid,ai_level,ai_order,aib_ownerdpid ai_ownerdpid,aib_budget ai_budget,aib_use ai_use 
from mps_account_item,mps_account_branch 
where ai_id=aib_aiid 
order by aib_bcid , ai_order,ai_level