| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 435 人关注过本帖
标题:请教:批量SQL命令如何在VFP里执行(不用存储过程实现)
取消只看楼主 加入收藏
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:287
专家分:38
注 册:2010-12-23
结帖率:59.49%
收藏
已结贴  问题点数:20 回复次数:3 
请教:批量SQL命令如何在VFP里执行(不用存储过程实现)
因为出于保密计算方法的原因不想在SQL数据库中建存储过程,有什么办法运行本来要建成存储过程的一大批T-SQL(sql代码如下),类似把下面的SQL脚本语句封装在VFP里执行

    --更新数据
    update a set a.oee_num=isnull(b.bd_num,0),a.oee_den=isnull(b.bd_total,0),
    a.cal_oee=round(case when isnull(b.bd_total,0)=0 then 0.00 else isnull(b.bd_num,0)/b.bd_total*100.0 end,2),
    a.oee_coef=isnull(b.bd_coef,1),
    a.dis_oee=round(case when isnull(b.bd_total,0)=0 then 0.00 else isnull(b.bd_num,0)/b.bd_total*100.0 end*isnull(b.bd_coef,1),2),
    a.modify_time=getdate()
    from ky_mcp.dbo.ky_mcp_oee a
    left join(
        select c.parent_location_id, b.location_id,b.date_code,b.data_type,b.bd_coef,sum(b.bd_num) as bd_num,sum(b.bd_total) as bd_total--,b.bd_cal_data,b.bd_coef,b.bd_dis_data
        from ky_bd_tmp_data b with(nolock)
        join bs_location c with(nolock) on b.location_id=c.location_id
        where b.bd_type='OEE'
        group by c.parent_location_id, b.location_id,b.date_code,b.data_type,b.bd_coef
    )b on a.wsp_id=b.parent_location_id and a.line_id=b.location_id and  a.day_type=b.date_code
   
    declare @wsp_id varchar(50),@tody varchar(10)
    declare ky_proc_mcp_oee_cursor_wsp cursor for
        select location_id
        from bs_location with(nolock)
        where parent_location_id='' and location_type_code='area' and is_delete=0
    open ky_proc_mcp_oee_cursor_wsp
    fetch next from ky_proc_mcp_oee_cursor_wsp into @wsp_id
    while @@FETCH_STATUS=0
    begin
        select @tody = right(dbo.get_shift_date(getdate(),'0',@wsp_id),10) --根据当前时刻判定当前是哪天
        update x set x.oee_num=isnull(y.oee_num,0),x.oee_den=isnull(y.oee_den,0),x.cal_oee=isnull(y.cal_oee,0),
        x.oee_coef= case when isnull(y.foee,0)=0 then 1 else y.foee end,
        x.dis_oee = round(isnull(y.cal_oee,0)*case when isnull(y.foee,0)=0 then 1 else y.foee end,2),
        x.modify_time=getdate()
        from dbo.ky_mcp_oee x
        left join (
            select e.parent_location_id,b.location_id,sum(isnull(user_num9,0))as oee_num,sum(isnull(d.time_open,0)*isnull(d.num_hour,0)) as oee_den,
            case when sum(isnull(d.time_open,0)*isnull(d.num_hour,0))>0 then round( sum(isnull(user_num9,0))/sum(isnull(d.time_open,0)*isnull(d.num_hour,0)) * 100,2) else 0 end as cal_oee,max(d.foee) as foee
            from ky_hch_eqptline d with(nolock)
            join(select max(id) as id from ky_hch_eqptline with(nolock) group by eqpt_id) dd on d.id=d.id
            join bs_eqpt_sub c with(nolock) on d.eqpt_id= c.eqpt_id
            join bs_eqpt_all b with(nolock) on c.sub_eqpt_id = b.eqpt_id
            left join ky_hch_daynum a with(nolock) on c.sub_eqpt_id=a.eqpt_id and a.wo_code= @tody
            join bs_location e with(nolock) on b.location_id=e.location_id
            where  b.res1 = '1' and e.parent_location_id=@wsp_id
            group by e.parent_location_id, b.location_id
        )y on  x.wsp_id=y.parent_location_id and x.line_id=y.location_id
        where x.day_type = 'TODAY' and x.wsp_id=@wsp_id

        fetch next from ky_proc_mcp_oee_cursor_wsp into @wsp_id
    end
    close ky_proc_mcp_oee_cursor_wsp
    deallocate ky_proc_mcp_oee_cursor_wsp

[此贴子已经被作者于2023-10-5 22:22编辑过]

搜索更多相关主题的帖子: with join from sum and 
2023-10-05 22:20
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:287
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 2楼 laowan001
转成文本后如何发给SQL执行呢
2023-10-06 10:01
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:287
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 4楼 csyx
不知道如何包装这么一大段字符串,然后用什么方法运行,这样可以吗?(注:Handle1是数据库连接)
TEXT TO cSQLchar  TEXTMERGE NOSHOW PRETEXT 7
    --更新数据
    update a set a.oee_num=isnull(b.bd_num,0),a.oee_den=isnull(b.bd_total,0),
    a.cal_oee=round(case when isnull(b.bd_total,0)=0 then 0.00 else isnull(b.bd_num,0)/b.bd_total*100.0 end,2),
    a.oee_coef=isnull(b.bd_coef,1),
    a.dis_oee=round(case when isnull(b.bd_total,0)=0 then 0.00 else isnull(b.bd_num,0)/b.bd_total*100.0 end*isnull(b.bd_coef,1),2),
    a.modify_time=getdate()
    from ky_mcp.dbo.ky_mcp_oee a
    left join(
        select c.parent_location_id, b.location_id,b.date_code,b.data_type,b.bd_coef,sum(b.bd_num) as bd_num,sum(b.bd_total) as bd_total--,b.bd_cal_data,b.bd_coef,b.bd_dis_data
        from ky_bd_tmp_data b with(nolock)
        join bs_location c with(nolock) on b.location_id=c.location_id
        where b.bd_type='OEE'
        group by c.parent_location_id, b.location_id,b.date_code,b.data_type,b.bd_coef
    )b on a.wsp_id=b.parent_location_id and a.line_id=b.location_id and  a.day_type=b.date_code
   
    declare @wsp_id varchar(50),@tody varchar(10)
    declare ky_proc_mcp_oee_cursor_wsp cursor for
        select location_id
        from bs_location with(nolock)
        where parent_location_id='' and location_type_code='area' and is_delete=0
    open ky_proc_mcp_oee_cursor_wsp
    fetch next from ky_proc_mcp_oee_cursor_wsp into @wsp_id
    while @@FETCH_STATUS=0
    begin
        select @tody = right(dbo.get_shift_date(getdate(),'0',@wsp_id),10) --根据当前时刻判定当前是哪天
        update x set x.oee_num=isnull(y.oee_num,0),x.oee_den=isnull(y.oee_den,0),x.cal_oee=isnull(y.cal_oee,0),
        x.oee_coef= case when isnull(y.foee,0)=0 then 1 else y.foee end,
        x.dis_oee = round(isnull(y.cal_oee,0)*case when isnull(y.foee,0)=0 then 1 else y.foee end,2),
        x.modify_time=getdate()
        from dbo.ky_mcp_oee x
        left join (
            select e.parent_location_id,b.location_id,sum(isnull(user_num9,0))as oee_num,sum(isnull(d.time_open,0)*isnull(d.num_hour,0)) as oee_den,
            case when sum(isnull(d.time_open,0)*isnull(d.num_hour,0))>0 then round( sum(isnull(user_num9,0))/sum(isnull(d.time_open,0)*isnull(d.num_hour,0)) * 100,2) else 0 end as cal_oee,max(d.foee) as foee
            from ky_hch_eqptline d with(nolock)
            join(select max(id) as id from ky_hch_eqptline with(nolock) group by eqpt_id) dd on d.id=d.id
            join bs_eqpt_sub c with(nolock) on d.eqpt_id= c.eqpt_id
            join bs_eqpt_all b with(nolock) on c.sub_eqpt_id = b.eqpt_id
            left join ky_hch_daynum a with(nolock) on c.sub_eqpt_id=a.eqpt_id and a.wo_code= @tody
            join bs_location e with(nolock) on b.location_id=e.location_id
            where  b.res1 = '1' and e.parent_location_id=@wsp_id
            group by e.parent_location_id, b.location_id
        )y on  x.wsp_id=y.parent_location_id and x.line_id=y.location_id
        where x.day_type = 'TODAY' and x.wsp_id=@wsp_id

        fetch next from ky_proc_mcp_oee_cursor_wsp into @wsp_id
    end
    close ky_proc_mcp_oee_cursor_wsp
    deallocate ky_proc_mcp_oee_cursor_wsp
ENDTEXT

Sqlexec(Handle1,cSQLchar,'')
2023-10-06 11:42
laibinhua
Rank: 2
等 级:论坛游民
威 望:1
帖 子:287
专家分:38
注 册:2010-12-23
收藏
得分:0 
回复 7楼 csyx
正确了,就用这个方法可以
2023-10-06 12:44
快速回复:请教:批量SQL命令如何在VFP里执行(不用存储过程实现)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015978 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved