作业中实现特定查询语句

Rotel-刘志东 2011-05-22 04:27:04
怎样实现已经插入的数据不要再重复插入,只插入inv1表中新增的数据插入到临时表yptc
----插入到临时表中
select T0.itemcode ,T0.Dscription ,T0.Whscode,T2.suppcatnum,T0.Quantity,T0.Priceafvat,T2.[LstEvlPric],T0.Quantity*T0.PriceafVat as 'price1' ,T2.[LstEvlPric]*T0.Quantity as 'cost' ,(T0.Quantity*T0.PriceafVat)-(T2.[LstEvlPric]*T0.Quantity) as'cost1',T0.U_003,T0.U_004,(T0.Quantity*T0.PriceafVat-T2.[LstEvlPric]*T0.Quantity)*T0.U_004 as 'total2',T0.DocEntry,T0.U_001,T0.U_002,T0.U_005,T0.U_008, T1.U_DocDate into yptc from inv1 T0 inner join oinv T1 on T0.DocEntry=T1.DocEntry inner join oitm T2 on T0.itemcode =T2.itemcode
and T0.U_004='0.08' and T0.itemcode<>'1000001' and T0.itemcode<>'40188888'
and CAST(T1.U_DocDate AS datetime) between '2010/05/19' and '2011/12/31'

把此查询写在了作业中,在某个特定的时间执行,如何实现。


...全文
136 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yibey 2011-05-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 rucypli 的回复:]
引用 3 楼 ssp2009 的回复:
作业调用存储过程。
.
[/Quote]


一般如果我遇到这样的问题会喜欢在inv1表中加入一个判断字段表示是否新插入的记录,然后在作业里对已经插入的数据,执行更新这个表inv1。。我想思路上会清晰很多,
rucypli 2011-05-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ssp2009 的回复:]
作业调用存储过程。
[/Quote].
qgqch2008 2011-05-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ssp2009 的回复:]

作业调用存储过程。
[/Quote]恩
快溜 2011-05-22
  • 打赏
  • 举报
回复
作业调用存储过程。
--小F-- 2011-05-22
  • 打赏
  • 举报
回复
写成一个存储过程 在调用的时候判断下 
if exists(select 1 from tb where ...)
begin
...
end
打一壶酱油 2011-05-22
  • 打赏
  • 举报
回复
加个 not exists 就行了

----插入到临时表中
insert into yptc 列1,列2,................................
select T0.itemcode ,T0.Dscription ,T0.Whscode,T2.suppcatnum,T0.Quantity,T0.Priceafvat,T2.[LstEvlPric],T0.Quantity*T0.PriceafVat as 'price1' ,T2.[LstEvlPric]*T0.Quantity as 'cost' ,(T0.Quantity*T0.PriceafVat)-(T2.[LstEvlPric]*T0.Quantity) as'cost1',T0.U_003,T0.U_004,(T0.Quantity*T0.PriceafVat-T2.[LstEvlPric]*T0.Quantity)*T0.U_004 as 'total2',T0.DocEntry,T0.U_001,T0.U_002,T0.U_005,T0.U_008, T1.U_DocDate into yptc from inv1 T0 inner join oinv T1 on T0.DocEntry=T1.DocEntry inner join oitm T2 on T0.itemcode =T2.itemcode
and T0.U_004='0.08' and T0.itemcode<>'1000001' and T0.itemcode<>'40188888'
and CAST(T1.U_DocDate AS datetime) between '2010/05/19' and '2011/12/31'
and not exists(select 1 from yptc b where b.主键 = T0.主键)

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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