sql问题

jujian_jianzhanyi 2011-02-28 02:27:47
create table tb2(tname varchar(50),er varchar(50))
insert into tb2

select a.use_Company,b.By_02 from HJ_ASS_Occupy_Detail a inner join HJ_ASS_Detail_Two b
on a.sid=b.nid where use_Company='第二分公司'

select distinct b.tname as tname,
replace(substring(b.er,a.number,charindex(',',b.er + ',',a.number) - a.number),'*','*台') er
into #t2
from tb2 b,master..spt_values a
where a.number between 1 and len(b.er)
and substring(',' + b.er,a.number,1) = ','

select stuff(er,charindex('台',er),len(er) - charindex('台',er) + 1,'') er
into #b2
from #t2

select * from #b2

select '合计' as tname,ltrim(a.aa) + '+' + ltrim(b.bb) + '*台' as er
from (select sum(cast(er as int))aa from #b2 where er not like '%*%')a,
(select sum(cast(replace(er,'*','') as int))bb from #b2 where er like '%*%')b




这段代码


insert into tb2

select a.use_Company,b.By_02 from HJ_ASS_Occupy_Detail a inner join HJ_ASS_Detail_Two b
on a.sid=b.nid where use_Company='第二分公司'
给tb2插入数据的时候是取的这张表中的数据,但是如果这两张表中的数据有修改的话

select '合计' as tname,ltrim(a.aa) + '+' + ltrim(b.bb) + '*台' as er
from (select sum(cast(er as int))aa from #b2 where er not like '%*%')a,
(select sum(cast(replace(er,'*','') as int))bb from #b2 where er like '%*%')b
他查出来的还是原来修改前的记录



怎么样让他自动改成修改后的数据
...全文
63 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jujian_jianzhanyi 2011-02-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 acherat 的回复:]
SQL code

--自动修改应该要用到触发器!建立在你修改的那个表上,动作发生在你要查的表。
[/Quote]

怎么写啊
AcHerat 2011-02-28
  • 打赏
  • 举报
回复

--自动修改应该要用到触发器!建立在你修改的那个表上,动作发生在你要查的表。

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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