在VB中怎么调用写好的SQL语句?

renjie45 2008-11-03 11:56:10
我的sql语句保存在一个文本文件中,内容
SET NOCOUNT Off
Create Table #jzc_DATA2 (
FItemID int null,
Fnumber varchar(255) null,
Fname varchar(255) null,
Fmodel varchar(255) null,
Funitid int null,
Funitname varchar(255) null,
FCustID int null,
Fcustname varchar(255) null,
FYWYID int null,
FYWYname varchar(255) null,
FOutQty float null,
FOutAmount Decimal(28,2) null)
Insert Into #jzc_DATA2 (FItemID,FCustID,FYWYID,FOutQty,FOutAmount)
Select v2.FItemID,v1.FSupplyID,v1.FEmpid,sum(v2.FQty),sum(v2.FconsignAmount)
From ICStockBill v1,ICStockBillEntry v2
Where v1.FTranType =21 And v1.FCancelLation=0 and v1.FInterID = v2.FInterID
AND v1.FDate >='2008-09-01' AND v1.FDate <='2008-09-30'
group by v1.Fempid,v1.fSupplyid,v2.fitemid

update t1 set t1.fnumber=t2.fnumber,t1.fname=t2.fname,t1.fmodel=t2.fmodel,t1.funitid=t2.funitid from #jzc_DATA2 t1,t_icitem t2 where t1.fitemid=t2.fitemid

update t1 set t1.fcustname=t2.fname from #jzc_DATA2 t1,t_Organization t2 where t1.fcustid=t2.FItemID

update t1 set t1.fywyname=t2.fname from #jzc_DATA2 t1,t_emp t2 where t1.fywyid=t2.FItemID

update t1 set t1.funitname=t2.fname from #jzc_DATA2 t1,t_unitgroup t2 where t1.Funitid=t2.Fdefaultunitid
Insert Into #jzc_DATA2
Select 200000+fywyid,'业务员小计','','','','',100000,'',Fywyid,'',sum(FoutQty),sum(FoutAmount)
From #jzc_DATA2 Group By Fywyid --业务员合计

Insert Into #jzc_DATA2
Select 100000+fcustid,'客户小计','','','','',fcustid,'',Fywyid,'',sum(FoutQty),sum(FoutAmount)
From #jzc_DATA2 where fcustid<>100000 Group By Fywyid,fcustid --在业务员下分客户小计

--delete #jzc_DATA2 where fnumber='客户小计' and

Insert Into #jzc_DATA2
Select 300000,'总计','','','','',299999,'',199999,'',sum(FoutQty),sum(FoutAmount)
From #jzc_DATA2 --总计

update t1 set t1.fnumber=t2.Fname+'业绩小计' from #jzc_DATA2 t1,t_emp t2 where t1.Fywyid=t2.fitemid and t1.fnumber='业务员小计'
update t1 set t1.fnumber=t2.Fname+'销售小计' from #jzc_DATA2 t1,t_Organization t2 where t1.FcustID=t2.FItemID and t1.fnumber='客户小计'

select Fywyname as '业务员',Fcustname AS '客户',Fnumber as '商品编码',Fname AS '商品名称',Fmodel AS '规格型号',Funitname AS '单位',FOutQty AS '数量',FOutAMOUNT AS '金额'
from #jzc_DATA2 order by Fywyid,Fcustid,Fitemid
--select * from #jzc_data2 order by fywyid,Fcustid,Fitemid
DROP TABLE #jzc_DATA2
--delete #jzc_DATA2
--select * from icstockbill where ftrantype=21 order by fEMPid and fEMPid=0 --43499

delete t2 from icstockbill t1,icstockbillentry t2
where t1.finterid=t2.finterid and t1.ftrantype=1 and t2.finterid<=9322 and t2.finterid>=7435
打开icstockbillentry 粘贴EXECL中的sheet3表
select * from icstockbill

我想让结果在datagrid控件中显示出来.
...全文
247 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
renjie45 2008-12-19
  • 打赏
  • 举报
回复
是K3里的,同行?
Amy_Dream 2008-11-12
  • 打赏
  • 举报
回复
存储过程,用参数变量、case when语句 等解决你经常修改的参数问题
白发程序猿 2008-11-12
  • 打赏
  • 举报
回复
这那是一个SQL语句,明显是一个存储过程
luzifa 2008-11-12
  • 打赏
  • 举报
回复
好象是K3的数据库表进行数据统计的?
tongnaifu 2008-11-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 renjie45 的回复:]
没有其他办法吗?因为sql语句经常变动的.
[/Quote]
怎么个变动法?不能用参数、case when 等变通解决吗?
zuoxingyu 2008-11-08
  • 打赏
  • 举报
回复
我还从没写过这么长的SQL语句呢

而且里面还包含建表,插入临时表,修改表,删除临时表

很好很强大
renjie45 2008-11-05
  • 打赏
  • 举报
回复
没有其他办法吗?因为sql语句经常变动的.
mustudent 2008-11-03
  • 打赏
  • 举报
回复
這么長,寫成sp然后VB調用吧
vbman2003 2008-11-03
  • 打赏
  • 举报
回复
没试过这样处理SQL语句
如果你是SQL数据库,可以试试在上面你的SQL文本中,给每一SQL语句加上结束符分号,然后在VB中一次读出内容到一个字符串中变量中,直接用ADO连接对象的execute方法执行....
tongnaifu 2008-11-03
  • 打赏
  • 举报
回复
http://www.cnblogs.com/tongnaifu/archive/2008/10/21/1316141.html
写成存储过程,然后执行返回recordset,设置datagrid的datasourse就好了

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧