IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[report_41_data]') AND type = 'P')
DROP PROCEDURE [dbo].[report_41_data]
GO
CREATE PROCEDURE report_41_data
@cmpid int,@branchid int,@userdpid int,@userotid int,@useruid int,@tableid varchar(8000),@objids varchar(8000),@pagesize int,@sf_tjrq varchar(512)
,@sf_jsrq varchar(512)
,@sf_fgs varchar(512)
,@sf_md varchar(512)
,@sf_tjr varchar(512)
,@sf_shr varchar(512)
,@sf_zt varchar(512)

AS
BEGIN
 set nocount on 

declare @dataIds table(objid int)
if @objids!='_NONE' and @objids!='_none_' and @objids!='' 
insert into @dataIds(objid)
select value from dbo.fn_split_int(@objids)
if @tableid='tb_report1'
begin
    if @pagesize=10000
    begin
       select ord_no,
ord_date,
ord_branch,
ord_createdepart,
ord_creator,
ord_sfqk,
ord_sjh,
ord_creator,
ord_tjrsjh,
ord_shr,
ord_status,
ord_shsj,
cu_account from order_270,mps_employee where ord_status != '已作废' 
and charindex('临',ord_no) = 0
and ord_createcuid = cu_id
and ((ord_date >= @sf_tjrq + ' 00:00:00' and ord_date <= @sf_jsrq + ' 23:59:59'))
and (@sf_fgs = '' or ord_branch = @sf_fgs)
and (@sf_md = '' or ord_createdepart = @sf_md)
and (@sf_tjr = '' or ord_creator = @sf_tjr )
and (@sf_shr = '' or ord_shr = @sf_shr)
and (@sf_zt = '' or ord_status = @sf_zt)

       return
    end
    if @objids!='_none_'
    begin
       select ord_no,
ord_date,
ord_branch,
ord_createdepart,
ord_creator,
ord_sfqk,
ord_sjh,
ord_creator,
ord_tjrsjh,
ord_shr,
ord_status,
ord_shsj,
cu_account from @dataIds,order_270,mps_employee where objid=ord_id  
       return
    end

end


select count(*) as dataCount from order_270,mps_employee where ord_status != '已作废' 
and charindex('临',ord_no) = 0
and ord_createcuid = cu_id
and ((ord_date >= @sf_tjrq + ' 00:00:00' and ord_date <= @sf_jsrq + ' 23:59:59'))
and (@sf_fgs = '' or ord_branch = @sf_fgs)
and (@sf_md = '' or ord_createdepart = @sf_md)
and (@sf_tjr = '' or ord_creator = @sf_tjr )
and (@sf_shr = '' or ord_shr = @sf_shr)
and (@sf_zt = '' or ord_status = @sf_zt)

select top 99990 ord_id as dataIds from order_270,mps_employee where ord_status != '已作废' 
and charindex('临',ord_no) = 0
and ord_createcuid = cu_id
and ((ord_date >= @sf_tjrq + ' 00:00:00' and ord_date <= @sf_jsrq + ' 23:59:59'))
and (@sf_fgs = '' or ord_branch = @sf_fgs)
and (@sf_md = '' or ord_createdepart = @sf_md)
and (@sf_tjr = '' or ord_creator = @sf_tjr )
and (@sf_shr = '' or ord_shr = @sf_shr)
and (@sf_zt = '' or ord_status = @sf_zt)
 order by ord_date desc
select top 10 'tb_report1' tableid ,ord_no,
ord_date,
ord_branch,
ord_createdepart,
ord_creator,
ord_sfqk,
ord_sjh,
ord_creator,
ord_tjrsjh,
ord_shr,
ord_status,
ord_shsj,
cu_account from order_270,mps_employee where ord_status != '已作废' 
and charindex('临',ord_no) = 0
and ord_createcuid = cu_id
and ((ord_date >= @sf_tjrq + ' 00:00:00' and ord_date <= @sf_jsrq + ' 23:59:59'))
and (@sf_fgs = '' or ord_branch = @sf_fgs)
and (@sf_md = '' or ord_createdepart = @sf_md)
and (@sf_tjr = '' or ord_creator = @sf_tjr )
and (@sf_shr = '' or ord_shr = @sf_shr)
and (@sf_zt = '' or ord_status = @sf_zt)
 order by ord_date desc

END