惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
P
Palo Alto Networks Blog
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Last Week in AI
Last Week in AI
Blog — PlanetScale
Blog — PlanetScale
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
The Cloudflare Blog
I
Intezer
P
Privacy International News Feed
C
Check Point Blog
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
B
Blog
Latest news
Latest news
小众软件
小众软件
Engineering at Meta
Engineering at Meta
Cyberwarzone
Cyberwarzone
Project Zero
Project Zero
P
Proofpoint News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Schneier on Security
美团技术团队
G
GRAHAM CLULEY
博客园 - 司徒正美
T
Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 叶小钗
C
Cisco Blogs
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
NISL@THU
NISL@THU
AWS News Blog
AWS News Blog
T
Threat Research - Cisco Blogs
月光博客
月光博客
Security Latest
Security Latest
Scott Helme
Scott Helme
T
Tenable Blog

博客园 - nerozhang

NHibernate小结(一) 数据库字符串处理 数据库中的字符串操作 通过查询语句链接到远程数据库 得到数据库表的结构 NHibernate Quick Start Guide 唐诗赏析--唐诗的起源,发展 PetShop 4.0的缓存处理 AggregateCacheDependency、CacheDependency、SqlCacheDependency Asp.net 2.0和PetShop4 的缓存示例 自定义 HttpModule 示例 在global.asax中实现URL重写(应用) Community Starter Kit - 结构 Community Starter Kit - 功能介绍 Community Starter Kit -简介 Petshop 4.0学习-MasterPage.master文件 PetShop 4.0学习-数据访问层之数据库访问设计 PetShop 4.0学习--登录以及注册功能的分析 PetShop 4.0学习--体系架构 PetShop 4.0学习--业务功能介绍
从两张表中取出不一致的数据
nerozhang · 2008-03-07 · via 博客园 - nerozhang

DECLARE @verify TABLE (h883id char(9not null)
DECLARE @outmemo TABLE (h883id char(9not null)
DECLARE @t1 TABLE (h883id char(9not null)

declare @strCorpID char(4)
declare @StartDate DateTime
declare @EndDate DateTime
declare @count int
set @strCorpID='C275'
--set @StartDate='1900-04-01'
--
set @EndDate = '2008-02-03'

select @startdate=startdate,@enddate=enddate from verifymain
where corpid=@strcorpid
--print @startdate
--
print @enddate

insert into @outmemo 
select distinct h883id from (
--成品报关出区:
select om.h883id,'成品' as goodstype,--ps.oriproductid,
ps.productpartno,ps.hscode,ps.chinesename,ps.spec,ps.type,
sum(oub.quantity) sumquantity ,ps.unit,
sum(oub.net) sumnet,sum(oub.gross) sumgross,sum(oub.price) sumamount,oub.currency,'报关出区' as billtype
from outmemo om join outunitebefore oub 
on om.outmemoid=oub.outmemoid and om.approve='1' and om.cancel='0'
    
join productstocks ps 
on ps.productstocksid=oub.productstocksid 
where om.corpid=@strCorpid and convert(char(10),om.approvetime,120)>=@StartDate 
and convert(char(10),om.approvetime,120)<=@EndDate 
group by om.h883id,ps.oriproductid,ps.productpartno,ps.hscode,
ps.chinesename,ps.spec,ps.type,ps.unit,oub.currency)t1

insert into @verify
select distinct h883id from (
select h883id from verify where corpid=@strcorpid and billtype='outmemo'
union all 
select h883id from verifydetail where corpid=@strcorpid and billtype='outmemo'
)t2

--获得@verify表中的记录数
select @count=count(*from @verify
print 'verify:'+cast(@count as char(10))+''

--获得@outmemo表中的记录数
select @count=count(*from @outmemo
print 'outmemo:'+cast(@count as char(10))+''

--取得两张表不一致的记录
--
首先取得两张表中共同的数据
insert into @t1
select v.h883id from @verify v join @outmemo o
on o.h883id=v.h883id

--得到两张表中不一致的记录
select h883id,'verify' as billtype from @verify
where h883id not in(select h883id from @t1)
union all
select h883id,'outmemo' as billtype from @outmemo
where h883id not in(select h883id from @t1)

使用了表变量,首先把需要比较的记录放到表变量中。然后根据表变量中的值查找出不一致的记录。