34,591
社区成员
发帖
与我相关
我的任务
分享
CREATE VIEW [汇总表]
AS
SELECT 'A'+A.ExcelServerRCID FROM [数据库A].[dbo].[表名]
UNION ALL SELECT 'B'+A.ExcelServerRCID FROM [数据库B].[dbo].[表名]
--每多一个账套,就加一个UNION ALL
如上所说,关键是 你们要能够把汇总查询转到这个视图上
if exists(select * from sysobjects where xtype ='u' and name ='mytable')
drop table mytable
go
create table mytable (id int identity, code varchar(20) , name varchar(30))
go
create trigger mytable_tr
on mytable after insert
as
begin
update mytable set code = 'A' + code
where id in (select id from inserted)
end
go
insert into mytable(code , name) values('201401010001' , '这是第一个测试数据')
insert into mytable(code , name) values('201401010002' , '这是第二个测试数据')
go
select * from mytable
go
id code name
----------- -------------------- ------------------------------
1 A201401010001 这是第一个测试数据
2 A201401010002 这是第二个测试数据
(2 行受影响)